org.cojen.util
Class WeakCanonicalSet<T>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<T>
org.cojen.util.WeakCanonicalSet<T>
- All Implemented Interfaces:
- Iterable<T>, Collection<T>, Set<T>
- Direct Known Subclasses:
- WeakFlyweightSet
public class WeakCanonicalSet<T>
- extends AbstractSet<T>
A thread-safe Set that manages canonical objects: sharable objects that are
typically immutable. Call the put method for supplying the
WeakCanonicalSet with candidate canonical instances.
Objects that do not customize the hashCode and equals methods don't make
sense to be canonicalized because each instance will be considered unique.
The object returned from the put method will always be the same
as the one passed in.
- Author:
- Brian S O'Neill
WeakCanonicalSet
public WeakCanonicalSet()
put
public <U extends T> U put(U obj)
- Pass in a candidate canonical object and get a unique instance from this
set. The returned object will always be of the same type as that passed
in. If the object passed in does not equal any object currently in the
set, it will be added to the set, becoming canonical.
- Parameters:
obj - candidate canonical object; null is also accepted
iterator
public Iterator<T> iterator()
- Specified by:
iterator in interface Iterable<T>- Specified by:
iterator in interface Collection<T>- Specified by:
iterator in interface Set<T>- Specified by:
iterator in class AbstractCollection<T>
size
public int size()
- Specified by:
size in interface Collection<T>- Specified by:
size in interface Set<T>- Specified by:
size in class AbstractCollection<T>
contains
public boolean contains(Object obj)
- Specified by:
contains in interface Collection<T>- Specified by:
contains in interface Set<T>- Overrides:
contains in class AbstractCollection<T>
toString
public String toString()
- Overrides:
toString in class AbstractCollection<T>
hashCode
protected int hashCode(Object obj)
equals
protected boolean equals(Object a,
Object b)
Copyright © 2004-2008 Brian S O'Neill. All Rights Reserved.