org.geotools.util
Class WeakHashSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by org.geotools.util.WeakHashSet<E>
Type Parameters:
E - The type of elements in the set.
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>, CheckedCollection<E>
Direct Known Subclasses:
CanonicalSet

public class WeakHashSet<E>
extends java.util.AbstractSet<E>
implements CheckedCollection<E>

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
Version:
$Id: WeakHashSet.java 31445 2008-09-07 18:14:23Z desruisseaux $
Author:
Martin Desruisseaux (IRD)
See Also:
WeakHashMap

Constructor Summary
WeakHashSet()
          Deprecated. Use WeakHashSet(Class).
WeakHashSet(java.lang.Class<E> type)
          Constructs a WeakHashSet.
 
Method Summary
 boolean add(E obj)
          Adds the specified element to this set if it is not already present.
 void clear()
          Removes all of the elements from this set.
 boolean contains(java.lang.Object obj)
          Returns true if this set contains the specified element.
 java.lang.Class<E> getElementType()
          Returns the element type.
 java.util.Iterator<E> iterator()
          Returns an iterator over the elements contained in this collection.
 boolean remove(java.lang.Object obj)
          Removes a single instance of the specified element from this set, if it is present
 int size()
          Returns the count of element in this set.
 E[] toArray()
          Returns a view of this set as an array.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, retainAll, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray
 
Methods inherited from interface java.util.Set
addAll, containsAll, isEmpty, retainAll, toArray
 

Constructor Detail

WeakHashSet

public WeakHashSet()
Deprecated. Use WeakHashSet(Class).

Constructs a WeakHashSet.


WeakHashSet

public WeakHashSet(java.lang.Class<E> type)
Constructs a WeakHashSet.

Parameters:
type - The type of the element to be included in this set.
Since:
2.5
Method Detail

getElementType

public java.lang.Class<E> getElementType()
Returns the element type.

Specified by:
getElementType in interface CheckedCollection<E>
Returns:
The element type.
Since:
2.5

size

public int size()
Returns the count of element in this set.

Specified by:
size in interface java.util.Collection<E>
Specified by:
size in interface java.util.Set<E>
Specified by:
size in class java.util.AbstractCollection<E>

contains

public boolean contains(java.lang.Object obj)
Returns true if this set contains the specified element.

Specified by:
contains in interface java.util.Collection<E>
Specified by:
contains in interface java.util.Set<E>
Overrides:
contains in class java.util.AbstractCollection<E>
Parameters:
obj - Object to be checked for containment in this set.
Returns:
true if this set contains the specified element.

remove

public boolean remove(java.lang.Object obj)
Removes a single instance of the specified element from this set, if it is present

Specified by:
remove in interface java.util.Collection<E>
Specified by:
remove in interface java.util.Set<E>
Overrides:
remove in class java.util.AbstractCollection<E>
Parameters:
obj - element to be removed from this set, if present.
Returns:
true if 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 returns false.

Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.Set<E>
Overrides:
add in class java.util.AbstractCollection<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 interface java.util.Collection<E>
Specified by:
clear in interface java.util.Set<E>
Overrides:
clear in class java.util.AbstractCollection<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:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.Set<E>
Overrides:
toArray in class java.util.AbstractCollection<E>

iterator

public java.util.Iterator<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.

Specified by:
iterator in interface java.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Specified by:
iterator in interface java.util.Set<E>
Specified by:
iterator in class java.util.AbstractCollection<E>


Copyright © 1996-2010 Geotools. All Rights Reserved.