Package org.geotools.util
Class WeakHashSet<E>
- Object
-
- AbstractCollection<E>
-
- AbstractSet<E>
-
- WeakHashSet<E>
-
- Type Parameters:
E- The type of elements in the set.
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Set<E>,CheckedCollection<E>
- Direct Known Subclasses:
CanonicalSet
public class WeakHashSet<E> extends AbstractSet<E> implements CheckedCollection<E>
A set of objects hold by weak references. An entry in aWeakHashSetwill automatically be removed when it is no longer in ordinary use. More precisely, the presence of an entry will not prevent the entry from being discarded by the garbage collector, that is, made finalizable, finalized, and then reclaimed. When an entry has been discarded it is effectively removed from the set, so this class behaves somewhat differently than otherSetimplementations.If you would like to use
WeakHashSetas inside a factory to prevent creating duplicate immutable objects, please look at theCanonicalSetsubclass.The
WeakHashSetclass is thread-safe.- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD)
- See Also:
WeakHashMap
-
-
Constructor Summary
Constructors Constructor Description WeakHashSet(Class<E> type)Constructs aWeakHashSet.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E obj)Adds the specified element to this set if it is not already present.voidclear()Removes all of the elements from this set.booleancontains(Object obj)Returnstrueif this set contains the specified element.Class<E>getElementType()Returns the element type.Iterator<E>iterator()Returns an iterator over the elements contained in this collection.booleanremove(Object obj)Removes a single instance of the specified element from this set, if it is presentintsize()Returns the count of element in this set.E[]toArray()Returns a view of this set as an array.-
Methods inherited from class AbstractSet
equals, hashCode, removeAll
-
Methods inherited from class AbstractCollection
addAll, containsAll, isEmpty, retainAll, toArray, toString
-
Methods inherited from interface Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface Set
addAll, containsAll, isEmpty, retainAll, spliterator, toArray
-
-
-
-
Method Detail
-
getElementType
public Class<E> getElementType()
Returns the element type.- Specified by:
getElementTypein interfaceCheckedCollection<E>- Returns:
- The element type.
- Since:
- 2.5
-
size
public int size()
Returns the count of element in this set.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
contains
public boolean contains(Object obj)
Returnstrueif this set contains the specified element.- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>- Parameters:
obj- Object to be checked for containment in this set.- Returns:
trueif this set contains the specified element.
-
remove
public boolean remove(Object obj)
Removes a single instance of the specified element from this set, if it is present- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>- Parameters:
obj- element to be removed from this set, if present.- Returns:
trueif the set contained the specified element.
-
add
public boolean add(E obj)
Adds the specified element to this set if it is not already present. If this set already contains the specified element, the call leaves this set unchanged and returnsfalse.- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>- Parameters:
obj- Element to be added to this set.- Returns:
trueif this set did not already contain the specified element.
-
clear
public void clear()
Removes all of the elements from this set.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
toArray
public E[] toArray()
Returns a view of this set as an array. Elements will be in an arbitrary order. Note that this array contains strong reference. Consequently, no object reclamation will occurs as long as a reference to this array is hold.- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classAbstractCollection<E>
-
-