com.triactive.jdo.util
Class InternPool

java.lang.Object
  extended byjava.util.AbstractCollection
      extended bycom.triactive.jdo.util.InternPool
All Implemented Interfaces:
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)

iterator

public java.util.Iterator iterator()

size

public int size()


Copyright 2001-2007 The TJDO Project All Rights Reserved.