Package org.jboss.util.collection
Class CachedCollection
- java.lang.Object
-
- java.util.AbstractCollection
-
- org.jboss.util.collection.CachedCollection
-
- All Implemented Interfaces:
java.lang.Iterable
,java.util.Collection
public class CachedCollection extends java.util.AbstractCollection
A wrapper around aCollection
which translates added objects intoSoftObject
references, allowing the VM to garbage collect objects in the collection when memory is low.- Version:
- $Revision$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
CachedCollection.MyIterator
A dereferencing iterator.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Collection
collection
Wrapped collectionprotected java.lang.ref.ReferenceQueue
queue
Reference queue
-
Constructor Summary
Constructors Constructor Description CachedCollection(java.util.Collection collection)
Construct a CachedCollection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
iterator
public java.util.Iterator iterator()
Returns an iterator over the elements contained in this collection.- Specified by:
iterator
in interfacejava.util.Collection
- Specified by:
iterator
in interfacejava.lang.Iterable
- Specified by:
iterator
in classjava.util.AbstractCollection
- Returns:
- An iterator over the elements contained in this collection.
-
size
public int size()
Returns the size of the collection.- Specified by:
size
in interfacejava.util.Collection
- Specified by:
size
in classjava.util.AbstractCollection
- Returns:
- The number of elements in the collection.
-
add
public boolean add(java.lang.Object obj)
Add an object to the collection.- Specified by:
add
in interfacejava.util.Collection
- Overrides:
add
in classjava.util.AbstractCollection
- Parameters:
obj
- Object (or null to add to the collection.- Returns:
- True if object was added.
-
maintain
private void maintain()
Maintains the collection by removing garbage collected objects.
-
-