FileDocCategorySizeDatePackage
IteratorPool.javaAPI DocJava SE 6 API3022Tue Jun 10 00:23:14 BST 2008com.sun.org.apache.xpath.internal.axes

IteratorPool

public class IteratorPool extends Object implements Serializable
Pool of object of a given type to pick from to help memory usage
xsl.usage
internal

Fields Summary
static final long
serialVersionUID
private final DTMIterator
m_orig
Type of objects in this pool.
private final Vector
m_freeStack
Vector of given objects this points to.
Constructors Summary
public IteratorPool(DTMIterator original)
Constructor IteratorPool

param
original The original iterator from which all others will be cloned.


                   
    
  
    m_orig = original;
    m_freeStack = new Vector();
  
Methods Summary
public synchronized voidfreeInstance(com.sun.org.apache.xml.internal.dtm.DTMIterator obj)
Add an instance of the given object to the pool

param
obj Object to add.

    m_freeStack.addElement(obj);
  
public synchronized com.sun.org.apache.xml.internal.dtm.DTMIteratorgetInstance()
Get an instance of the given object in this pool

return
An instance of the given object

    // Check if the pool is empty.
    if (m_freeStack.isEmpty())
    {

      // Create a new object if so.
      try
      {
        return (DTMIterator)m_orig.clone();
      }
      catch (Exception ex)
      {
        throw new WrappedRuntimeException(ex);
      }
    }
    else
    {
      // Remove object from end of free pool.
      DTMIterator result = (DTMIterator)m_freeStack.lastElement();

      m_freeStack.setSize(m_freeStack.size() - 1);

      return result;
    }
  
public synchronized com.sun.org.apache.xml.internal.dtm.DTMIteratorgetInstanceOrThrow()
Get an instance of the given object in this pool

return
An instance of the given object

    // Check if the pool is empty.
    if (m_freeStack.isEmpty())
    {

      // Create a new object if so.
      return (DTMIterator)m_orig.clone();
    }
    else
    {
      // Remove object from end of free pool.
      DTMIterator result = (DTMIterator)m_freeStack.lastElement();

      m_freeStack.setSize(m_freeStack.size() - 1);

      return result;
    }