ObjectPool

open class ObjectPool<T>

This class define a simple template of object pool pattern.

Example:

val customPool = ObjectPool<Int>()

Since

1.4.0

Inheritors

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
var objects: HashMap<String, T>
Link copied to clipboard
val size: Int

Pool size

Functions

Link copied to clipboard
fun first(): T

Returns the first value or throws an exception if pool is empty.

Link copied to clipboard
inline fun firstOrElse(defaultValue: () -> T): T

Returns the first value, or the result of the defaultValue function if there was no entry.

Link copied to clipboard
fun firstOrNull(): T?

Returns the first value, or null if this pool contains no entry.

Link copied to clipboard
operator fun get(key: String): T

Returns the value for the given key or throws an exception if there is no such key in the pool.

Link copied to clipboard
inline fun getOrElse(key: String, defaultValue: () -> T): T

Returns the value for the given key, or the result of the defaultValue function if there was no entry for the given key.

Link copied to clipboard
fun getOrNull(key: String): T?

Returns the value to which the specified key is mapped, or null if this pool contains no mapping for the key.

Link copied to clipboard
fun last(): T

Returns the last value or throws an exception if pool is empty.

Link copied to clipboard
inline fun lastOrElse(defaultValue: () -> T): T

Returns the last value, or the result of the defaultValue function if there was no entry.

Link copied to clipboard
fun lastOrNull(): T?

Returns the last value, or null if this pool contains no entry.

Link copied to clipboard
operator fun set(key: String, value: T)

Allows to use the index operator for storing values in a pool.