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.Cloneable
A 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.ReferenceQueue
queue
The reference queue used to get object removal notifications.protected java.util.Set
serialized_set
protected java.util.Set
set
The 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 boolean
add(java.lang.Object obj)
Add an element to the set.void
clear()
Removes all of the elements from this set.java.lang.Object
clone()
Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned.boolean
contains(java.lang.Object obj)
Returns true if this set contains the specified element.protected void
expungeStaleEntries()
Remove garbage collected entries.boolean
isEmpty()
Returns true if this set contains no elements.java.util.Iterator
iterator()
Return an iteration over the elements in the set.protected java.lang.Object
readResolve()
Perform special handling on serialization.boolean
remove(java.lang.Object obj)
Removes the given element from this set if it is present.int
size()
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.Object
writeReplace()
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:
contains
in interfacejava.util.Collection<T>
- Specified by:
contains
in interfacejava.util.Set<T>
- Overrides:
contains
in 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:
clone
in 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.ObjectStreamException
Perform special handling on serialization.- Throws:
java.io.ObjectStreamException
-
readResolve
protected java.lang.Object readResolve() throws java.io.ObjectStreamException
Perform special handling on serialization.- Throws:
java.io.ObjectStreamException
-
-