| java.util.AbstractSet org.geotools.util.WeakHashSet
All known Subclasses: org.geotools.util.CanonicalSet,
WeakHashSet | public class WeakHashSet extends AbstractSet (Code) | | 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 27862 2007-11-12 19:51:19Z desruisseaux $ author: Martin Desruisseaux See Also: WeakHashMap |
Field Summary | |
final static int | ADD The "add" operation. | final static int | GET The "get" operation. | final static int | INTERN The "intern" operation. | final static int | REMOVE The "remove" operation. |
Constructor Summary | |
public | WeakHashSet() Constructs a
WeakHashSet . |
Method Summary | |
public synchronized boolean | add(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
false .
Parameters: obj - Element to be added to this set. | public synchronized Object | canonicalize(Object object) Returns an object equals to
object if such an object already exist in this
WeakHashSet . | public synchronized void | canonicalize(Object[] objects) Iteratively call
WeakHashSet.canonicalize(Object) for an array of objects. | public synchronized void | clear() Removes all of the elements from this set. | public boolean | contains(Object obj) Returns
true if this set contains the specified element.
Parameters: obj - Object to be checked for containment in this set. | public synchronized Object | get(Object obj) Returns an object equals to the specified object, if present. | final Object | intern(Object obj, int operation) Returns an object equals to
obj if such an object already
exist in this
WeakHashSet . | public Iterator | iterator() Returns an iterator over the elements contained in this collection. | public synchronized boolean | remove(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. | public synchronized int | size() Returns the count of element in this set. | public synchronized Object[] | toArray() Returns a view of this set as an array. |
ADD | final static int ADD(Code) | | The "add" operation.
|
GET | final static int GET(Code) | | The "get" operation.
|
INTERN | final static int INTERN(Code) | | The "intern" operation.
|
REMOVE | final static int REMOVE(Code) | | The "remove" operation.
|
WeakHashSet | public WeakHashSet()(Code) | | Constructs a
WeakHashSet .
|
add | public synchronized boolean add(Object obj)(Code) | | 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 .
Parameters: obj - Element to be added to this set. true if this set did not alreadycontain the specified element. |
canonicalize | public synchronized Object canonicalize(Object object)(Code) | | Returns an object equals to
object if such an object already exist in this
WeakHashSet . Otherwise, adds
object to this
WeakHashSet .
This method is equivalents to the following code:
if (object != null) {
Object current = get(object);
if (current != null) {
return current;
} else {
add(object);
}
}
return object;
CanonicalSet |
clear | public synchronized void clear()(Code) | | Removes all of the elements from this set.
|
contains | public boolean contains(Object obj)(Code) | | Returns
true if this set contains the specified element.
Parameters: obj - Object to be checked for containment in this set. true if this set contains the specified element. |
get | public synchronized Object get(Object obj)(Code) | | Returns an object equals to the specified object, if present. If
this set doesn't contains any object equals to
obj ,
then this method returns
null .
CanonicalSet |
intern | final Object intern(Object obj, int operation)(Code) | | Returns an object equals to
obj if such an object already
exist in this
WeakHashSet . Otherwise, add
obj to this
WeakHashSet . 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;
|
iterator | public Iterator iterator()(Code) | | 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.
|
remove | public synchronized boolean remove(Object obj)(Code) | | 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. true if the set contained the specified element. |
size | public synchronized int size()(Code) | | Returns the count of element in this set.
|
toArray | public synchronized Object[] toArray()(Code) | | 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.
|
|
|