public abstract class Pool<T> extends Object
Pools| Modifier and Type | Field and Description |
|---|---|
int |
max
The maximum number of objects that will be pooled.
|
| Constructor and Description |
|---|
Pool()
Creates a pool with an initial capacity of 16 and no maximum.
|
Pool(int initialCapacity)
Creates a pool with the specified initial capacity and no maximum.
|
Pool(int initialCapacity,
int max)
Creates a pool with the specified initial capacity and maximum.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all free objects from this pool.
|
void |
free(T object)
Puts the specified object in the pool, making it eligible to be returned by
obtain(). |
void |
freeAll(Array<T> objects)
Puts the specified objects in the pool.
|
int |
getFree()
The number of objects available to be obtained.
|
protected abstract T |
newObject() |
T |
obtain()
The object may be new (from
newObject()) or reused (previously freed). |
protected void |
reset(T object)
Called when an object is freed to clear the state of the object for possible later reuse.
|
public Pool()
public Pool(int initialCapacity)
initialCapacity - initial pool capacitypublic Pool(int initialCapacity,
int max)
initialCapacity - initial pool capacitymax - the maximum number of free objects to store in this poolprotected abstract T newObject()
public T obtain()
newObject()) or reused (previously freed).public void free(T object)
obtain().
If the pool already contains max free objects, the specified object is reset but not added to the pool.object - the object to put in the poolIllegalArgumentException - if object is nullprotected void reset(T object)
Poolable.reset() if the object is Poolable.object - the object to freepublic void freeAll(Array<T> objects)
objects - an array of objects to put back in the poolIllegalArgumentException - if objects is nullfree(Object)public void clear()
public int getFree()
Copyright © 2018. All rights reserved.