This class is used by UlidCreator.
You can use this class if you need to use a specific random generator
strategy. However, most people just need UlidCreator.
Instances of this class can behave in one of two ways: monotonic or non-monotonic (default).
If the factory is monotonic, the random component is incremented by 1 if more than one ULID is generated within the same millisecond.
The maximum ULIDs that can be generated per millisecond is 2^80.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreate()Returns a new ULID.create(long time) Returns a new ULID.static UlidFactoryReturns a new factory.static UlidFactorynewInstance(IntFunction<byte[]> randomFunction) Returns a new factory.static UlidFactorynewInstance(LongSupplier randomFunction) Returns a new factory.static UlidFactorynewInstance(Random random) Returns a new factory.static UlidFactoryReturns a new monotonic factory.static UlidFactorynewMonotonicInstance(IntFunction<byte[]> randomFunction) Returns a new monotonic factory.static UlidFactorynewMonotonicInstance(IntFunction<byte[]> randomFunction, LongSupplier timeFunction) Returns a new monotonic factory.static UlidFactorynewMonotonicInstance(LongSupplier randomFunction) Returns a new monotonic factory.static UlidFactorynewMonotonicInstance(LongSupplier randomFunction, LongSupplier timeFunction) Returns a new monotonic factory.static UlidFactorynewMonotonicInstance(Random random) Returns a new monotonic factory.static UlidFactorynewMonotonicInstance(Random random, LongSupplier timeFunction) Returns a new monotonic factory.
-
Constructor Details
-
UlidFactory
public UlidFactory()Default constructor.
-
-
Method Details
-
newInstance
Returns a new factory.It is equivalent to the default constructor
new UlidFactory().- Returns:
UlidFactory
-
newInstance
Returns a new factory.- Parameters:
random- aRandomgenerator- Returns:
UlidFactory
-
newInstance
Returns a new factory.The given random function must return a long value.
- Parameters:
randomFunction- a random function that returns a long value- Returns:
UlidFactory
-
newInstance
Returns a new factory.The given random function must return a byte array.
- Parameters:
randomFunction- a random function that returns a byte array- Returns:
UlidFactory
-
newMonotonicInstance
Returns a new monotonic factory.- Returns:
UlidFactory
-
newMonotonicInstance
Returns a new monotonic factory.- Parameters:
random- aRandomgenerator- Returns:
UlidFactory
-
newMonotonicInstance
Returns a new monotonic factory.The given random function must return a long value.
- Parameters:
randomFunction- a random function that returns a long value- Returns:
UlidFactory
-
newMonotonicInstance
Returns a new monotonic factory.The given random function must return a byte array.
- Parameters:
randomFunction- a random function that returns a byte array- Returns:
UlidFactory
-
newMonotonicInstance
Returns a new monotonic factory.- Parameters:
random- aRandomgeneratortimeFunction- a function that returns the current time in milliseconds, measured from the UNIX epoch of 1970-01-01T00:00Z (UTC)- Returns:
UlidFactory
-
newMonotonicInstance
public static UlidFactory newMonotonicInstance(LongSupplier randomFunction, LongSupplier timeFunction) Returns a new monotonic factory.The given random function must return a long value.
- Parameters:
randomFunction- a random function that returns a long valuetimeFunction- a function that returns the current time in milliseconds, measured from the UNIX epoch of 1970-01-01T00:00Z (UTC)- Returns:
UlidFactory
-
newMonotonicInstance
public static UlidFactory newMonotonicInstance(IntFunction<byte[]> randomFunction, LongSupplier timeFunction) Returns a new monotonic factory.The given random function must return a byte array.
- Parameters:
randomFunction- a random function that returns a byte arraytimeFunction- a function that returns the current time in milliseconds, measured from the UNIX epoch of 1970-01-01T00:00Z (UTC)- Returns:
UlidFactory
-
create
Returns a new ULID.- Returns:
- a ULID
-
create
Returns a new ULID.- Parameters:
time- the current time in milliseconds, measured from the UNIX epoch of 1970-01-01T00:00Z (UTC)- Returns:
- a ULID
-