Package jadex.collection
Class WeakSet<T>
java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractSet<T>
jadex.collection.WeakSet<T>
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<T>,Collection<T>,Set<T>
A weak set for entries that will be automatically removed when
no references to them are existing any more.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ReferenceQueueThe reference queue used to get object removal notifications.protected Setprotected SetThe set which will be used for element storage. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd an element to the set.voidclear()Removes all of the elements from this set.clone()Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned.booleanReturns true if this set contains the specified element.protected final voidRemove garbage collected entries.booleanisEmpty()Returns true if this set contains no elements.iterator()Return an iteration over the elements in the set.protected ObjectPerform special handling on serialization.booleanRemoves the given element from this set if it is present.intsize()Return the size of the set.Object[]toArray()Convert the set to an array.Object[]Convert the set to an array.protected ObjectPerform special handling on serialization.Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAllMethods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
addAll, containsAll, retainAll, spliterator
-
Field Details
-
set
The set which will be used for element storage. -
queue
The reference queue used to get object removal notifications. -
serialized_set
-
-
Constructor Details
-
WeakSet
public WeakSet()Construct a WeakSet based on a HashSet.
-
-
Method Details
-
size
public int size()Return the size of the set.- Specified by:
sizein interfaceCollection<T>- Specified by:
sizein interfaceSet<T>- Specified by:
sizein classAbstractCollection<T>- Returns:
- The size of the set.
-
iterator
Return an iteration over the elements in the set. -
toArray
Convert the set to an array.- Specified by:
toArrayin interfaceCollection<T>- Specified by:
toArrayin interfaceSet<T>- Overrides:
toArrayin classAbstractCollection<T>
-
toArray
Convert the set to an array.- Specified by:
toArrayin interfaceCollection<T>- Specified by:
toArrayin interfaceSet<T>- Overrides:
toArrayin classAbstractCollection<T>
-
add
Add an element to the set.- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceSet<T>- Overrides:
addin classAbstractCollection<T>- 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 interfaceCollection<T>- Specified by:
isEmptyin interfaceSet<T>- Overrides:
isEmptyin classAbstractCollection<T>- Returns:
- true if this set contains no elements.
-
contains
Returns true if this set contains the specified element.- Specified by:
containsin interfaceCollection<T>- Specified by:
containsin interfaceSet<T>- Overrides:
containsin classAbstractCollection<T>- Parameters:
obj- Element whose presence in this set is to be tested.- Returns:
- true if this set contains the specified element.
-
remove
Removes the given element from this set if it is present.- Specified by:
removein interfaceCollection<T>- Specified by:
removein interfaceSet<T>- Overrides:
removein classAbstractCollection<T>- 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 interfaceCollection<T>- Specified by:
clearin interfaceSet<T>- Overrides:
clearin classAbstractCollection<T>
-
clone
Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned. -
expungeStaleEntries
protected final void expungeStaleEntries()Remove garbage collected entries. -
writeReplace
Perform special handling on serialization.- Throws:
ObjectStreamException
-
readResolve
Perform special handling on serialization.- Throws:
ObjectStreamException
-