Methods Summary |
---|
public boolean | add(java.lang.Object ob)Unsupported.
throw new UnsupportedOperationException();
|
public boolean | addAll(java.util.Collection coll)Unsupported.
throw new UnsupportedOperationException();
|
public void | cache(java.lang.Object key, java.lang.Object val)Caches the specified object identified by the specified key.
cache.put(key, new SoftReference(val));
|
public void | clear()Clears the entire cache.
cache.clear();
|
public boolean | contains(java.lang.Object ob)Checks the specified object against the cache and verifies that it
is in the cache. This method will return
false if the object was once in the cache
but has expired due to inactivity.
Iterator it = cache.values().iterator();
while( it.hasNext() ) {
SoftReference ref = (SoftReference)it.next();
Object item = ref.get();
if( item != null && ob.equals(item) ) {
return true;
}
}
return false;
|
public boolean | containsAll(java.util.Collection coll)Checks the passed in collection and determines if all elements
of that collection are contained within this cache. Care should
be taken in reading too much into a failure. If one of the elements
was once in this cache but has expired due to inactivity, this
method will return false.
Iterator it = coll.iterator();
while( it.hasNext() ) {
if( !contains(it.next()) ) {
return false;
}
}
return true;
|
public boolean | containsKey(java.lang.Object key)Checks if an object with the specified key is in the cache.
if( !cache.containsKey(key) ) {
return false;
}
else {
SoftReference ref = (SoftReference)cache.get(key);
if( ref.get() == null ) {
release(key);
return false;
}
return true;
}
|
public java.lang.Object | get(java.lang.Object key)Provides the cached object identified by the specified key. This
method will return null if the
specified object is not in the cache.
SoftReference ref = (SoftReference)cache.get(key);
Object ob;
if( ref == null ) {
return null;
}
ob = ref.get();
if( ob == null ) {
release(key);
}
return ob;
|
public boolean | isEmpty()
return cache.isEmpty();
|
public java.util.Iterator | iterator()Provides all of the valid objects in the cache.
This method will not be the snappiest method in the world.
return toList().iterator();
|
public void | release(java.lang.Object key)Releases the specified object from the cache.
cache.remove(key);
|
public boolean | remove(java.lang.Object ob)Unsupported.
throw new UnsupportedOperationException();
|
public boolean | removeAll(java.util.Collection coll)Unsupported.
throw new UnsupportedOperationException();
|
public boolean | retainAll(java.util.Collection coll)Unsupported.
throw new UnsupportedOperationException();
|
public int | size()
return toList().size();
|
public java.lang.Object[] | toArray()
return toList().toArray();
|
public java.lang.Object[] | toArray(java.lang.Object[] arr)
return toList().toArray(arr);
|
private java.util.ArrayList | toList()
Iterator it = cache.values().iterator();
ArrayList tmp = new ArrayList();
while( it.hasNext() ) {
SoftReference ref = (SoftReference)it.next();
Object ob = ref.get();
if( ob != null ) {
tmp.add(ob);
}
}
return tmp;
|