Class ClockSequenceController
- java.lang.Object
-
- com.github.f4b6a3.uuid.strategy.clockseq.ClockSequenceController
-
public final class ClockSequenceController extends Object
Class that controls the usage of clock sequence values from 0 to 16383. It manages a pool of 16384 values. The pool is implemented as an array of 2048 bytes (16384 bits). Each bit of this array corresponds to a pool value.
-
-
Constructor Summary
Constructors Constructor Description ClockSequenceController()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intborrow(int give, int take)Borrow a value from the pool and give back another value to the same pool.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 pool.booleanisFree(int value)Check if a value is free in the pool.booleanisUsed(int value)Check if a value is used out of the pool.
-
-
-
Method Detail
-
borrow
public int borrow(int give, int take)Borrow a value from the pool and give back another value to the same pool. If the value to be borrowed 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:
give- value to be given back to the pooltake- value to be taken from the pool- Returns:
- the 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.
-
-