org.geotools.util
Class WeakHashSet

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended byorg.geotools.util.WeakHashSet
All Implemented Interfaces:
java.util.Collection, java.util.Set

public class WeakHashSet
extends java.util.AbstractSet

A set of objects hold by weak references. An entry in a will automatically be removed when it is no longer in ordinary use. More precisely, the presence of a 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.

has a get(java.lang.Object) method that is not part of the Set interface. This method fetch an entry from this set that is equals to the supplied object. This is a convenient way to use as a pool of immutable objects.

The class is thread-safe.

Since:
2.0
Version:
$Id: WeakHashSet.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
WeakHashMap

Constructor Summary
WeakHashSet()
          Construct a .
 
Method Summary
 boolean add(java.lang.Object obj)
          Adds the specified element to this set if it is not already present.
 java.lang.Object canonicalize(java.lang.Object object)
          Returns an object equals to if such an object already exist in this .
 void canonicalize(java.lang.Object[] objects)
          Iteratively call canonicalize(Object) for an array of objects.
 void clear()
          Removes all of the elements from this set.
 boolean contains(java.lang.Object obj)
          Returns if this set contains the specified element.
 java.lang.Object get(java.lang.Object obj)
          Returns an object equals to the specified object, if present.
 java.util.Iterator 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.
 java.lang.Object[] 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.Set
addAll, containsAll, isEmpty, retainAll, toArray
 

Constructor Detail

WeakHashSet

public WeakHashSet()
Construct a .

Method Detail

size

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


contains

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

Parameters:
obj - Object to be checked for containment in this set.
Returns:
if this set contains the specified element.

get

public java.lang.Object get(java.lang.Object obj)
Returns an object equals to the specified object, if present. If this set doesn't contains any object equals to , then this method returns .

See Also:
canonicalize(Object)

remove

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

Parameters:
obj - element to be removed from this set, if present.
Returns:
if the set contained the specified element.

add

public boolean add(java.lang.Object 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 .

Parameters:
obj - Element to be added to this set.
Returns:
if this set did not already contain the specified element.

canonicalize

public java.lang.Object canonicalize(java.lang.Object object)
Returns an object equals to if such an object already exist in this . Otherwise, add to this . This method is equivalents to the following code:
    if (object!=null)
    {
        final Object current=get(object);
        if (current!=null) return current;
        else add(object);
    }
    return object;
 


canonicalize

public void canonicalize(java.lang.Object[] objects)
Iteratively call canonicalize(Object) for an array of objects. This method is equivalents to the following code:
    for (int i=0; i


clear

public void clear()
Removes all of the elements from this set.


toArray

public java.lang.Object[] 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.


iterator

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



Copyright © GeoTools. All Rights Reserved.