Package net.ssehub.easy.basics.pool
Class Pool<T>
java.lang.Object
net.ssehub.easy.basics.pool.Pool<T>
- Type Parameters:
T- the type of instances to be managed
Implements a simple pool for explicit memory management of frequently
created elements. In order to keep interfaces of instances clean, we
delegate creation and clear operation to the
IPoolManager delegate.- Author:
- Holger Eichelberger
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPool(IPoolManager<T> manager) Creates a new pool for a given type of instances represented by its pool manager. -
Method Summary
Modifier and TypeMethodDescriptionprivate booleancontainsByRef(T instance) Returns whether the pool already containsinstance.Returns an instance from the pool or creates a new instance via themanager.voidreleaseInstance(T instance)
-
Field Details
-
manager
-
pool
-
-
Constructor Details
-
Pool
Creates a new pool for a given type of instances represented by its pool manager.- Parameters:
manager- the pool manager
-
-
Method Details
-
getInstance
Returns an instance from the pool or creates a new instance via themanager.- Returns:
- an instance
-
releaseInstance
- Parameters:
instance- the instance to be released (ignored if null)
-
containsByRef
Returns whether the pool already containsinstance.- Parameters:
instance- the instance to look for (by reference)- Returns:
trueif the reference is already there,falseelse
-