org.cojen.util
Class WeakCanonicalSet
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet
org.cojen.util.WeakCanonicalSet
- All Implemented Interfaces:
- Iterable, Collection, Set
- Direct Known Subclasses:
- WeakFlyweightSet
public class WeakCanonicalSet
- extends AbstractSet
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 Object put(Object 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 iterator()
- Specified by:
iterator
in interface Iterable
- Specified by:
iterator
in interface Collection
- Specified by:
iterator
in interface Set
- Specified by:
iterator
in class AbstractCollection
size
public int size()
- Specified by:
size
in interface Collection
- Specified by:
size
in interface Set
- Specified by:
size
in class AbstractCollection
contains
public boolean contains(Object obj)
- Specified by:
contains
in interface Collection
- Specified by:
contains
in interface Set
- Overrides:
contains
in class AbstractCollection
toString
public String toString()
- Overrides:
toString
in class AbstractCollection
hashCode
protected int hashCode(Object obj)
equals
protected boolean equals(Object a,
Object b)
Copyright © 2004-2011 Brian S O'Neill. All Rights Reserved.