planetj.util
Class WeakCollection

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--planetj.util.WeakCollection
All Implemented Interfaces:
Collection, Serializable

public class WeakCollection
extends AbstractCollection
implements 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(Collection c)
          WeakCollection constructor
 
Method Summary
 boolean add(Object o)
          Adds a item to this collection
 Object get()
          Gets a single item out of the Collection.
 boolean isEmpty()
          Returns true if this collection contains no elements.
 Iterator iterator()
          Returns an iterator over the elements contained in this collection.
 boolean remove(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(Collection c)
WeakCollection constructor

Method Detail

add

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

Specified by:
add in interface Collection
Overrides:
add in class AbstractCollection

get

public 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 Collection
Overrides:
isEmpty in class AbstractCollection
Returns:
true if this collection contains no elements.

iterator

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

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

remove

public boolean remove(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 Collection
Overrides:
remove in class AbstractCollection
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 Collection
Specified by:
size in class AbstractCollection
Returns:
the number of elements in this collection.