public final class UlidFactory extends Object
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.
| 构造器和说明 |
|---|
UlidFactory()
Default constructor.
|
| 限定符和类型 | 方法和说明 |
|---|---|
Ulid |
create()
Returns a new ULID.
|
Ulid |
create(long time)
Returns a new ULID.
|
static UlidFactory |
newInstance()
Returns a new factory.
|
static UlidFactory |
newInstance(IntFunction<byte[]> randomFunction)
Returns a new factory.
|
static UlidFactory |
newInstance(LongSupplier randomFunction)
Returns a new factory.
|
static UlidFactory |
newInstance(Random random)
Returns a new factory.
|
static UlidFactory |
newMonotonicInstance()
Returns a new monotonic factory.
|
static UlidFactory |
newMonotonicInstance(IntFunction<byte[]> randomFunction)
Returns a new monotonic factory.
|
static UlidFactory |
newMonotonicInstance(IntFunction<byte[]> randomFunction,
LongSupplier timeFunction)
Returns a new monotonic factory.
|
static UlidFactory |
newMonotonicInstance(LongSupplier randomFunction)
Returns a new monotonic factory.
|
static UlidFactory |
newMonotonicInstance(LongSupplier randomFunction,
LongSupplier timeFunction)
Returns a new monotonic factory.
|
static UlidFactory |
newMonotonicInstance(Random random)
Returns a new monotonic factory.
|
static UlidFactory |
newMonotonicInstance(Random random,
LongSupplier timeFunction)
Returns a new monotonic factory.
|
public static UlidFactory newInstance()
It is equivalent to the default constructor new UlidFactory().
UlidFactorypublic static UlidFactory newInstance(Random random)
random - a Random generatorUlidFactorypublic static UlidFactory newInstance(LongSupplier randomFunction)
The given random function must return a long value.
randomFunction - a random function that returns a long valueUlidFactorypublic static UlidFactory newInstance(IntFunction<byte[]> randomFunction)
The given random function must return a byte array.
randomFunction - a random function that returns a byte arrayUlidFactorypublic static UlidFactory newMonotonicInstance()
UlidFactorypublic static UlidFactory newMonotonicInstance(Random random)
random - a Random generatorUlidFactorypublic static UlidFactory newMonotonicInstance(LongSupplier randomFunction)
The given random function must return a long value.
randomFunction - a random function that returns a long valueUlidFactorypublic static UlidFactory newMonotonicInstance(IntFunction<byte[]> randomFunction)
The given random function must return a byte array.
randomFunction - a random function that returns a byte arrayUlidFactorypublic static UlidFactory newMonotonicInstance(Random random, LongSupplier timeFunction)
random - a Random generatortimeFunction - a function that returns the current time in milliseconds,
measured from the UNIX epoch of 1970-01-01T00:00Z (UTC)UlidFactorypublic static UlidFactory newMonotonicInstance(LongSupplier randomFunction, LongSupplier timeFunction)
The given random function must return a long value.
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)UlidFactorypublic static UlidFactory newMonotonicInstance(IntFunction<byte[]> randomFunction, LongSupplier timeFunction)
The given random function must return a byte array.
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)UlidFactorypublic Ulid create()
public Ulid create(long time)
time - the current time in milliseconds, measured from the UNIX epoch of
1970-01-01T00:00Z (UTC)Copyright © 2025 fossc. All rights reserved.