org.cojen.util
Class WeakCanonicalSet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet
          extended by 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

Constructor Summary
WeakCanonicalSet()
           
 
Method Summary
 boolean contains(Object obj)
           
protected  boolean equals(Object a, Object b)
           
protected  int hashCode(Object obj)
           
 Iterator iterator()
           
 Object put(Object obj)
          Pass in a candidate canonical object and get a unique instance from this set.
 int size()
           
 String toString()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, isEmpty, remove, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, containsAll, isEmpty, remove, retainAll, toArray, toArray
 

Constructor Detail

WeakCanonicalSet

public WeakCanonicalSet()
Method Detail

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.