org.jgap.impl
Class Pool

java.lang.Object
  extended by org.jgap.impl.Pool

public class Pool
extends java.lang.Object

A simple, generic pool class that can be used to pool any kind of object. Objects can be released to this pool, either individually or as a Collection, and then later acquired again. It is not necessary for an object to have been originally acquired from the pool in order for it to be released to the pool. If there are no objects present in the pool, an attempt to acquire one will return null. The number of objects available in the pool can be determined with the size() method. Finally, it should be noted that the pool does not attempt to perform any kind of cleanup or re-initialization on the objects to restore them to some clean state when they are released to the pool; it's up to the user to reset any necessary state in the object prior to the release call (or just after the acquire call).


Constructor Summary
Pool()
          Constructor.
 
Method Summary
 java.lang.Object acquirePooledObject()
          Attempts to acquire an Object instance from the pool.
 void clear()
          Empties out this pool of all objects.
 void releaseAllObjects(java.util.Collection a_objectsToPool)
          Releases a Collection of objects to the pool.
 void releaseObject(java.lang.Object a_objectToPool)
          Releases an Object to the pool.
 int size()
          Retrieves the number of objects currently available in this pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pool

public Pool()
Constructor.

Method Detail

acquirePooledObject

public java.lang.Object acquirePooledObject()
Attempts to acquire an Object instance from the pool. It should be noted that no cleanup or re-initialization occurs on these objects, so it's up to the caller to reset the state of the returned Object if that's desirable.

Returns:
An Object instance from the pool or null if no Object instances are available in the pool.

releaseObject

public void releaseObject(java.lang.Object a_objectToPool)
Releases an Object to the pool. It's not required that the Object originated from the pool--any Object can be released to it.

Parameters:
a_objectToPool - The Object instance to be released into the pool.

releaseAllObjects

public void releaseAllObjects(java.util.Collection a_objectsToPool)
Releases a Collection of objects to the pool. It's not required that the objects in the Collection originated from the pool--any objects can be released to it.

Parameters:
a_objectsToPool - The Collection of objects to release into the pool.

size

public int size()
Retrieves the number of objects currently available in this pool.

Returns:
the number of objects in this pool.

clear

public void clear()
Empties out this pool of all objects.