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
A set of objects hold by weak references. An entry in a
WeakHashSet
will 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 other Set
implementations.
If you would like to use WeakHashSet
as inside a factory to prevent creating duplicate immutable objects,
please look at the CanonicalSet
subclass.
The WeakHashSet
class is thread-safe.
- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds the specified element to this set if it is not already present.void
clear()
Removes all of the elements from this set.boolean
Returnstrue
if this set contains the specified element.Returns the element type.iterator()
Returns an iterator over the elements contained in this collection.boolean
Removes a single instance of the specified element from this set, if it is presentint
size()
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
-
Constructor Details
-
WeakHashSet
Constructs aWeakHashSet
.- Parameters:
type
- The type of the element to be included in this set.- Since:
- 2.5
-
-
Method Details
-
getElementType
Returns the element type.- Specified by:
getElementType
in interfaceCheckedCollection<E>
- Returns:
- The element type.
- Since:
- 2.5
-
size
public int size()Returns the count of element in this set.- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
-
contains
Returnstrue
if this set contains the specified element.- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceSet<E>
- Overrides:
contains
in classAbstractCollection<E>
- Parameters:
obj
- Object to be checked for containment in this set.- Returns:
true
if this set contains the specified element.
-
remove
Removes a single instance of the specified element from this set, if it is present- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classAbstractCollection<E>
- Parameters:
obj
- element to be removed from this set, if present.- Returns:
true
if the set contained the specified element.
-
add
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:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Overrides:
add
in classAbstractCollection<E>
- Parameters:
obj
- Element to be added to this set.- Returns:
true
if this set did not already contain the specified element.
-
clear
public void clear()Removes all of the elements from this set.- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Overrides:
clear
in classAbstractCollection<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:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
iterator
Returns an iterator over the elements contained in this collection. No element from this set will be garbage collected as long as a reference to the iterator is hold.
-