Package org.jboss.util.collection
Class WeakSet
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet
-
- org.jboss.util.collection.WeakSet
-
- All Implemented Interfaces:
java.lang.Iterable,java.util.Collection,java.util.Set
public class WeakSet extends java.util.AbstractSet implements java.util.SetA Set implementation with weak elements. An entry in a WeakSet will automatically be removed when the element is no longer in ordinary use. More precisely, the presence of an given element will not prevent the element from being discarded by the garbage collector, that is, made finalizable, finalized, and then reclaimed.- Version:
- $Revision$
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(java.lang.Object obj)Add an element to the set.voidclear()Removes all of the elements from this set.java.lang.Objectclone()Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned.booleancontains(java.lang.Object obj)Returns true if this set contains the specified element.booleanisEmpty()Returns true if this set contains no elements.java.util.Iteratoriterator()Return an iteration over the elements in the set.protected voidmaintain()Maintain the elements in the set.booleanremove(java.lang.Object obj)Removes the given element from this set if it is present.intsize()Return the size of the set.-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
-
-
-
-
Constructor Detail
-
WeakSet
public WeakSet(java.util.Set set)
Construct a WeakSet. Any elements in the given set will be wrapped inWeakObjectreferences.- Parameters:
set- The Set which will be used for element storage.- Throws:
NullArgumentException- Set is null.
-
WeakSet
public WeakSet()
Construct a WeakSet based on a HashSet.
-
-
Method Detail
-
maintain
protected final void maintain()
Maintain the elements in the set. Removes objects from the set that have been reclaimed due to GC.
-
size
public int size()
Return the size of the set.- Specified by:
sizein interfacejava.util.Collection- Specified by:
sizein interfacejava.util.Set- Specified by:
sizein classjava.util.AbstractCollection- Returns:
- The size of the set.
-
iterator
public java.util.Iterator iterator()
Return an iteration over the elements in the set.- Specified by:
iteratorin interfacejava.util.Collection- Specified by:
iteratorin interfacejava.lang.Iterable- Specified by:
iteratorin interfacejava.util.Set- Specified by:
iteratorin classjava.util.AbstractCollection- Returns:
- An iteration over the elements in the set.
-
add
public boolean add(java.lang.Object obj)
Add an element to the set.- Specified by:
addin interfacejava.util.Collection- Specified by:
addin interfacejava.util.Set- Overrides:
addin classjava.util.AbstractCollection- Parameters:
obj- Element to add to the set.- Returns:
- True if the element was added.
-
isEmpty
public boolean isEmpty()
Returns true if this set contains no elements.- Specified by:
isEmptyin interfacejava.util.Collection- Specified by:
isEmptyin interfacejava.util.Set- Overrides:
isEmptyin classjava.util.AbstractCollection- Returns:
- true if this set contains no elements.
-
contains
public boolean contains(java.lang.Object obj)
Returns true if this set contains the specified element.- Specified by:
containsin interfacejava.util.Collection- Specified by:
containsin interfacejava.util.Set- Overrides:
containsin classjava.util.AbstractCollection- Parameters:
obj- Element whose presence in this set is to be tested.- Returns:
- true if this set contains the specified element.
-
remove
public boolean remove(java.lang.Object obj)
Removes the given element from this set if it is present.- Specified by:
removein interfacejava.util.Collection- Specified by:
removein interfacejava.util.Set- Overrides:
removein classjava.util.AbstractCollection- Parameters:
obj- Object to be removed from this set, if present.- Returns:
- true if the set contained the specified element.
-
clear
public void clear()
Removes all of the elements from this set.- Specified by:
clearin interfacejava.util.Collection- Specified by:
clearin interfacejava.util.Set- Overrides:
clearin classjava.util.AbstractCollection
-
clone
public java.lang.Object clone()
Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned.- Overrides:
clonein classjava.lang.Object- Returns:
- A shallow copy of this set.
-
-