Module com.github.f4b6a3.uuid
Class ClockSeqFunction.ClockSeqPool
- java.lang.Object
-
- com.github.f4b6a3.uuid.factory.function.ClockSeqFunction.ClockSeqPool
-
- Enclosing interface:
- ClockSeqFunction
public static final class ClockSeqFunction.ClockSeqPool extends Object
Nested class that manages a pool of 16384 clock sequence values.The pool is implemented as an array of 2048 bytes (16384 bits). Each bit of the array corresponds to a clock sequence value.
It is used to avoid that two time-based factories use the same clock sequence at same time in a class loader.
-
-
Constructor Summary
Constructors Constructor Description ClockSeqPool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearPool()Clear all bits of the byte array that represents the pool.intcountFree()Count the free values in the pool.intcountUsed()Count the used values out of the poolbooleanisFree(int value)Check if a value is free in the pool.booleanisUsed(int value)Check if a value is used out of the pool.intrandom()Take a random value from the pool.inttake(int take)Take a value from the pool.
-
-
-
Field Detail
-
POOL_MIN
public static final int POOL_MIN
- See Also:
- Constant Field Values
-
POOL_MAX
public static final int POOL_MAX
- See Also:
- Constant Field Values
-
-
Method Detail
-
take
public int take(int take)
Take a value from the pool.If the value to be taken is already in use, it is incremented until a free value is found and returned.
In the case that all pool values are in use, the pool is cleared and the last incremented value is returned.
It does nothing to negative arguments.
- Parameters:
take- value to be taken from the pool- Returns:
- the value to be borrowed if not used
-
random
public int random()
Take a random value from the pool.- Returns:
- the random value to be borrowed if not used
-
isUsed
public boolean isUsed(int value)
Check if a value is used out of the pool.- Parameters:
value- a value to be checked in the pool- Returns:
- true if the value is used
-
isFree
public boolean isFree(int value)
Check if a value is free in the pool.- Parameters:
value- a value to be checked in the pool- Returns:
- true if the value is free
-
countUsed
public int countUsed()
Count the used values out of the pool- Returns:
- the count of used values
-
countFree
public int countFree()
Count the free values in the pool.- Returns:
- the count of free values
-
clearPool
public void clearPool()
Clear all bits of the byte array that represents the pool.This corresponds to marking all pool values as free
-
-