org.riotfamily.common.collection
Class WeakReferenceCollection<T>

java.lang.Object
  extended by java.util.AbstractCollection<T>
      extended by org.riotfamily.common.collection.WeakReferenceCollection<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>

public class WeakReferenceCollection<T>
extends AbstractCollection<T>

Collection whose values are stored as weak references.

Since:
6.4
Author:
Felix Gnass [fgnass at neteye dot de]

Constructor Summary
WeakReferenceCollection()
           
 
Method Summary
 boolean add(T value)
          Adds a WeakReference referring to the given value to the internal collection of references.
 void clear()
          Clears the collection.
 Iterator<T> iterator()
          Returns an iterator over all non-cleared values.
 void purge()
          Removes all cleared references from the internal collection.
 int size()
          Returns the number of references.
 
Methods inherited from class java.util.AbstractCollection
addAll, 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
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

WeakReferenceCollection

public WeakReferenceCollection()
Method Detail

iterator

public Iterator<T> iterator()
Returns an iterator over all non-cleared values.

Specified by:
iterator in interface Iterable<T>
Specified by:
iterator in interface Collection<T>
Specified by:
iterator in class AbstractCollection<T>

size

public int size()
Returns the number of references. The number may include references that have already been cleared. To get an exact count call purge() before.

Specified by:
size in interface Collection<T>
Specified by:
size in class AbstractCollection<T>

add

public boolean add(T value)
Adds a WeakReference referring to the given value to the internal collection of references.

Specified by:
add in interface Collection<T>
Overrides:
add in class AbstractCollection<T>

clear

public void clear()
Clears the collection.

Specified by:
clear in interface Collection<T>
Overrides:
clear in class AbstractCollection<T>

purge

public void purge()
Removes all cleared references from the internal collection.