planetj.util
Class WeakCollection

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byplanetj.util.WeakCollection
All Implemented Interfaces:
java.util.Collection, java.io.Serializable

public class WeakCollection
extends java.util.AbstractCollection
implements java.io.Serializable

A Collection which does not prevent items from being garbage collected. If there are no other references to an item which has been added to a WeakCollection then that item will be garbage collected (and removed from that WeakCollection). This means that the size of a WeakCollection may diminish as time goes by even if no objects are directly removed from it.

A WeakCollection is not thread-safe, even if none of the threads are altering its contents.

See Also:
Serialized Form

Constructor Summary
WeakCollection()
          WeakCollection constructor
WeakCollection(java.util.Collection c)
          WeakCollection constructor
 
Method Summary
 boolean add(java.lang.Object o)
          Adds a item to this collection
 java.lang.Object get()
          Gets a single item out of the Collection.
 boolean isEmpty()
          Returns true if this collection contains no elements.
 java.util.Iterator iterator()
          Returns an iterator over the elements contained in this collection.
 boolean remove(java.lang.Object o)
          Removes an item from this collection.
 int size()
          Returns the number of elements in this collection.
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

WeakCollection

public WeakCollection()
WeakCollection constructor


WeakCollection

public WeakCollection(java.util.Collection c)
WeakCollection constructor

Method Detail

add

public boolean add(java.lang.Object o)
Adds a item to this collection

Specified by:
add in interface java.util.Collection

get

public java.lang.Object get()
Gets a single item out of the Collection. This is probably the "first" item in this Collection, but there is no guarantee which item will be returned. Null is returned if there are no elements present.


isEmpty

public boolean isEmpty()
Returns true if this collection contains no elements.

Specified by:
isEmpty in interface java.util.Collection
Returns:
true if this collection contains no elements.

iterator

public java.util.Iterator iterator()
Returns an iterator over the elements contained in this collection.

Specified by:
iterator in interface java.util.Collection
Returns:
an iterator over the elements contained in this collection.

remove

public boolean remove(java.lang.Object o)
Removes an item from this collection. If this element is in this collection multiple times, then one of its occurrences will be removed.

Specified by:
remove in interface java.util.Collection
Returns:
true if a item was removed; false otherwise

size

public int size()
Returns the number of elements in this collection. If the collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface java.util.Collection
Returns:
the number of elements in this collection.