Package jadex.commons.collection
Class WeakSet<T>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<T>
-
- jadex.commons.collection.WeakSet<T>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<T>,java.util.Collection<T>,java.util.Set<T>
public class WeakSet<T> extends java.util.AbstractSet<T> implements java.io.Serializable, java.lang.CloneableA weak set for entries that will be automatically removed when no references to them are existing any more.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ref.ReferenceQueuequeueThe reference queue used to get object removal notifications.protected java.util.Setserialized_setprotected java.util.SetsetThe set which will be used for element storage.
-
Constructor Summary
Constructors Constructor Description WeakSet()Construct a WeakSet based on a HashSet.
-
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.protected voidexpungeStaleEntries()Remove garbage collected entries.booleanisEmpty()Returns true if this set contains no elements.java.util.Iteratoriterator()Return an iteration over the elements in the set.protected java.lang.ObjectreadResolve()Perform special handling on serialization.booleanremove(java.lang.Object obj)Removes the given element from this set if it is present.intsize()Return the size of the set.java.lang.Object[]toArray()Convert the set to an array.java.lang.Object[]toArray(java.lang.Object[] result)Convert the set to an array.protected java.lang.ObjectwriteReplace()Perform special handling on serialization.
-
-
-
Method Detail
-
size
public int size()
Return the size of the set.
-
iterator
public java.util.Iterator iterator()
Return an iteration over the elements in the set.
-
toArray
public java.lang.Object[] toArray()
Convert the set to an array.
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] result)
Convert the set to an array.
-
add
public boolean add(java.lang.Object obj)
Add an element to the set.
-
isEmpty
public boolean isEmpty()
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<T>- Specified by:
containsin interfacejava.util.Set<T>- Overrides:
containsin classjava.util.AbstractCollection<T>- 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.
-
clear
public void clear()
Removes all of the elements from this set.
-
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.
-
expungeStaleEntries
protected final void expungeStaleEntries()
Remove garbage collected entries.
-
writeReplace
protected java.lang.Object writeReplace() throws java.io.ObjectStreamExceptionPerform special handling on serialization.- Throws:
java.io.ObjectStreamException
-
readResolve
protected java.lang.Object readResolve() throws java.io.ObjectStreamExceptionPerform special handling on serialization.- Throws:
java.io.ObjectStreamException
-
-