com.ls.util
Class Pool

java.lang.Object
  |
  +--com.ls.util.Pool

public class Pool
extends Object

Provides a pool of Objects.

Version:
$Revision: 1.2 $
Author:
Last modified by $Author: TBerk $

Field Summary
protected  List indexPool
          Pool of indexes to indicate which objects are available.
protected static Boolean OBJECT_AVAILABLE
          Status: object is available.
protected static Boolean OBJECT_NOT_AVAILABLE
          Status: object is not available.
protected  List objectPool
          Pool of objects.
protected  int poolSize
          Normal pool size.
 
Constructor Summary
Pool(int defaultPoolSize)
          Creates a new pool object and set the normal pool size.
Pool(List newObjectPool)
          Creates a new pool object and fills it with the given vector (pool).
 
Method Summary
 void check(IPoolObjectValidationCheckStrategy strategy)
          This method allows the user to specify an algorithm (strategy) for checking all pool objects by implementing the interface IPoolObjectValidationCheckStrategy.
 Object get()
          Returns (removes) an object from the pool.
 boolean put(Object newObject)
          This method adds an object to the pool, but only if the object is not null.
 boolean replace(Object oldObject, Object newObject)
          Replaces the old object with the new one.
 void setPoolSize(int newPoolSize)
          Sets the normal pool size.
NOTE: It doesn't set the current pool size!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

objectPool

protected List objectPool
Pool of objects.

indexPool

protected List indexPool
Pool of indexes to indicate which objects are available.

poolSize

protected int poolSize
Normal pool size.

OBJECT_AVAILABLE

protected static final Boolean OBJECT_AVAILABLE
Status: object is available.

OBJECT_NOT_AVAILABLE

protected static final Boolean OBJECT_NOT_AVAILABLE
Status: object is not available.
Constructor Detail

Pool

public Pool(int defaultPoolSize)
Creates a new pool object and set the normal pool size.
Parameters:
defaultPoolSize - The default pool size.

Pool

public Pool(List newObjectPool)
     throws IllegalArgumentException
Creates a new pool object and fills it with the given vector (pool).
Parameters:
newObjectPool - The new pool.
Throws:
IllegalArgumentException - If parameter newObjectPool is null.
Method Detail

put

public boolean put(Object newObject)
            throws IllegalArgumentException
This method adds an object to the pool, but only if the object is not null. If the object is already in the pool it's status will be set to available for reuse.
Parameters:
newObject - The new object.
Returns:
True if the object could be successfully put back - false otherwise.
Throws:
IllegalArgumentException - If parameter newObject is null.

get

public Object get()
           throws PoolObjectNotAvailableException
Returns (removes) an object from the pool. If there are more objects in the pool than the normal number the object will be removed from the pool. Otherwise the object will be set to not available.
Returns:
An object from the pool.
Throws:
PoolObjectNotAvailableException - If there is no more pool object available.

replace

public boolean replace(Object oldObject,
                       Object newObject)
                throws IllegalArgumentException
Replaces the old object with the new one.
Parameters:
oldObject - The old object.
newObject - The new object.
Returns:
True, if replacement was successful - otherwise false.
Throws:
IllegalArgumentException - If one parameter is null.

check

public void check(IPoolObjectValidationCheckStrategy strategy)
This method allows the user to specify an algorithm (strategy) for checking all pool objects by implementing the interface IPoolObjectValidationCheckStrategy.
Parameters:
strategy - User defined strategy for checking all pool objects.

setPoolSize

public void setPoolSize(int newPoolSize)
Sets the normal pool size.
NOTE: It doesn't set the current pool size!
This method can be used for increasing/decreasing the default pool size.
Parameters:
newPoolSize - The new pool size.