com.crankuptheamps.client
Class Pool<T>

java.lang.Object
  extended by com.crankuptheamps.client.Pool<T>
Type Parameters:
T - The pooled type.

public class Pool<T>
extends Object

A simple generic instance pool for objects that take a while to construct.


Constructor Summary
Pool(Class<T> theClass, int initialSize)
          Constructs a pool with the given size
 
Method Summary
 T get()
          Returns an object from the pool, growing self if necessary (by initialSize).
 void returnToPool(T theInstance)
          Return an object to the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pool

public Pool(Class<T> theClass,
            int initialSize)
Constructs a pool with the given size

Parameters:
theClass - The Class pooled. Should always be T.class. Sorry we can't do this ourselves.
initialSize - The initial size of the pool. If you pass a value less than 1, we'll just use 1.
Method Detail

get

public T get()
Returns an object from the pool, growing self if necessary (by initialSize). If T cannot be instantiated, returns null.

Returns:
A pooled instance.

returnToPool

public void returnToPool(T theInstance)
Return an object to the pool. Note, you're responsible for clear/reset of objects being returned.

Parameters:
theInstance - The T to return to the pool.