public class CachedCollection
extends java.util.AbstractCollection
Collection which translates added objects
into SoftObject references, allowing the VM to garbage collect
objects in the collection when memory is low.| Modifier and Type | Class and Description |
|---|---|
private class |
CachedCollection.MyIterator
A dereferencing iterator.
|
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Collection |
collection
Wrapped collection
|
protected java.lang.ref.ReferenceQueue |
queue
Reference queue
|
| Constructor and Description |
|---|
CachedCollection(java.util.Collection collection)
Construct a CachedCollection.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(java.lang.Object obj)
Add an object to the collection.
|
java.util.Iterator |
iterator()
Returns an iterator over the elements contained in this collection.
|
private void |
maintain()
Maintains the collection by removing garbage collected objects.
|
int |
size()
Returns the size of the collection.
|
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitprotected final java.lang.ref.ReferenceQueue queue
protected final java.util.Collection collection
public CachedCollection(java.util.Collection collection)
collection - Collection to wrap.public java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in class java.util.AbstractCollectionpublic int size()
size in interface java.util.Collectionsize in class java.util.AbstractCollectionpublic boolean add(java.lang.Object obj)
add in interface java.util.Collectionadd in class java.util.AbstractCollectionobj - Object (or null to add to the collection.private void maintain()