| |
|
| org.geotools.util.WeakHashSet org.geotools.util.CanonicalSet
CanonicalSet | public class CanonicalSet extends WeakHashSet (Code) | | A canonical set of objects, used to optimize memory use.
The operation of this set is similar in spirit to the
String.intern method.
The following example shows a convenient way to use
CanonicalSet as an
internal pool of immutable objects.
public Foo create(String definition) {
Foo created = new Foo(definition);
return (Foo) canonicalSet.unique(created);
}
The
CanonicalSet has a
CanonicalSet.get method that is not part of the
Set interface. This
get method retrieves an entry from this set that is equals to
the supplied object. The
CanonicalSet.unique method combines a
get followed by a
put operation if the specified object was not in the set.
The set of objects is held by weak references as explained in
WeakHashSet .
The
CanonicalSet class is thread-safe.
since: 2.4 version: $Id: CanonicalSet.java 25949 2007-06-20 16:07:37Z desruisseaux $ author: Martin Desruisseaux author: Jody Garnett |
Constructor Summary | |
public | CanonicalSet() Constructs a
CanonicalSet . |
Method Summary | |
public synchronized Object | get(Object object) Returns an object equals to the specified object, if present. | public synchronized Object | unique(Object object) Returns an object equals to
object if such an object already exist in this
CanonicalSet . | public synchronized void | uniques(Object[] objects) Iteratively call
CanonicalSet.unique(Object) for an array of objects. |
CanonicalSet | public CanonicalSet()(Code) | | Constructs a
CanonicalSet .
|
get | public synchronized Object get(Object object)(Code) | | Returns an object equals to the specified object, if present. If
this set doesn't contains any object equals to
object ,
then this method returns
null .
See Also: CanonicalSet.unique(Object) |
unique | public synchronized Object unique(Object object)(Code) | | Returns an object equals to
object if such an object already exist in this
CanonicalSet . Otherwise, adds
object to this
CanonicalSet .
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;
|
uniques | public synchronized void uniques(Object[] objects)(Code) | | Iteratively call
CanonicalSet.unique(Object) for an array of objects.
This method is equivalents to the following code:
for (int i=0; i
|
|
|
|