com.triactive.jdo.util
Class InternPool

java.lang.Object
  extended by java.util.AbstractCollection
      extended by com.triactive.jdo.util.InternPool
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection

public class InternPool
extends java.util.AbstractCollection

Implements a pool of internalized objects. Used to implement pools that behave like the one used by String.intern().

This implementation is synchronized. It is a generic collection that is unmodifiable with the exception of the intern(java.lang.Object) method.

Author:
Mike Martin

Constructor Summary
InternPool()
           
 
Method Summary
 boolean contains(java.lang.Object o)
           
 java.lang.Object intern(java.lang.Object candidate)
          Returns a canonical representation for the specified object.
 java.util.Iterator iterator()
           
 int size()
           
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

InternPool

public InternPool()
Method Detail

intern

public java.lang.Object intern(java.lang.Object candidate)
Returns a canonical representation for the specified object.

This method behaves much like String.intern(). A pool of objects, initially empty, is maintained privately.

If the pool already contains an object equal to the specified object as determined by the equals(Object) method, then the object from the pool is returned. Otherwise, the specified object is added to the pool and a reference to the specified object is returned.

It follows that for any two objects o1 and o2, intern(o1) == intern(o2) is true if and only if o1.equals(o2) is true.

Parameters:
candidate - the object to internalize
Returns:
an object that is equivalent to the specified object, but is guaranteed to be from a pool of unique objects.

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection
Overrides:
contains in class java.util.AbstractCollection

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in class java.util.AbstractCollection

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in class java.util.AbstractCollection


Copyright ? 2001-2007 The TJDO Project All Rights Reserved.