Class LinkedPool<E>
java.lang.Object
de.tomatengames.util.pool.LinkedPool<E>
- Type Parameters:
E- The type of object managed by this pool.
- All Implemented Interfaces:
Pool<E>
-
Constructor Summary
ConstructorsConstructorDescriptionLinkedPool(Supplier<E> factory) Constructs a newLinkedPoolwith the specified supplier for creating objects and an unlimited capacity.LinkedPool(Supplier<E> factory, long capacity) Constructs a newLinkedPoolwith the specified supplier for creating objects and a given capacity. -
Method Summary
Modifier and TypeMethodDescriptionlongcapacity()Returns the maximum capacity of the pool.claim()Claims an instance ofPooledfrom the pool.voidclean()Cleans up the pool by reducing its size to the minimum size recorded since the last clean operation.voidreduce(long newSize) Reduces the size of the pool to a specified new size.longsize()Returns the amount of stored objects currently in the pool.
-
Constructor Details
-
LinkedPool
-
LinkedPool
Constructs a newLinkedPoolwith the specified supplier for creating objects and a given capacity.- Parameters:
factory- A supplier function that provides instances of typeE.capacity- The maximum number of objects that will be stored in the pool.
-
-
Method Details
-
capacity
public long capacity()Returns the maximum capacity of the pool. The capacity limits the amount of stored objects in the pool.- Returns:
- The maximum number of objects that will be stored in the pool.
-
size
public long size()Returns the amount of stored objects currently in the pool.- Returns:
- The current number of objects in the pool.
-
clean
public void clean()Cleans up the pool by reducing its size to the minimum size recorded since the last clean operation.Call this regularly for active cleaning.
-
reduce
public void reduce(long newSize) Reduces the size of the pool to a specified new size. If the given new size is larger than the current amount of stored objects in the pool, nothing happens.- Parameters:
newSize- The desired new size of the pool.- Throws:
IllegalArgumentException- If the new size is negative.
-
claim
Description copied from interface:PoolClaims an instance ofPooledfrom the pool.When done with the object, it may be returned to the pool using either the
Pooled.free()method or thePooled.close()method. Do not call both, that would be a double-free.It is valid to not return ("steal") a claimed object to the pool. That prevents the pool from providing that object ever again.
-