com.go.trove.util
Class FlyweightSet

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractSet
              |
              +--com.go.trove.util.FlyweightSet
All Implemented Interfaces:
java.util.Collection, java.util.Set

public class FlyweightSet
extends java.util.AbstractSet

A thread-safe Set that manages flyweights: sharable objects that are usually immutable. Call the get method for supplying the FlyweightSet with candidate flyweight instances.

Objects that do not customize the hashCode and equals methods don't make sense to use as flyweights because each instance will be considered unique. The object returned from the get method will always be the same as the one passed in.

Version:
1 , 00/12/18
Author:
Brian S O'Neill
See Also:
Utils.intern(java.lang.Object)

Constructor Summary
FlyweightSet()
           
 
Method Summary
 boolean contains(java.lang.Object obj)
           
protected  boolean equals(java.lang.Object a, java.lang.Object b)
           
protected  int hashCode(java.lang.Object obj)
           
 java.util.Iterator iterator()
           
 java.lang.Object put(java.lang.Object obj)
          Pass in a candidate flyweight object and get a unique instance from this set.
 int size()
           
 java.lang.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

FlyweightSet

public FlyweightSet()
Method Detail

put

public java.lang.Object put(java.lang.Object obj)
Pass in a candidate flyweight 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 a flyweight.
Parameters:
obj - candidate flyweight; null is also accepted

iterator

public java.util.Iterator iterator()
Overrides:
iterator in class java.util.AbstractCollection

size

public int size()
Overrides:
size in class java.util.AbstractCollection

contains

public boolean contains(java.lang.Object obj)
Overrides:
contains in class java.util.AbstractCollection

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection

hashCode

protected int hashCode(java.lang.Object obj)

equals

protected boolean equals(java.lang.Object a,
                         java.lang.Object b)