public static class TsidFactory.Builder extends Object
It is used to setup a custom TsidFactory.
| 构造器和说明 |
|---|
Builder() |
| 限定符和类型 | 方法和说明 |
|---|---|
TsidFactory |
build()
Returns a build TSID factory.
|
TsidFactory.Builder |
withClock(java.time.Clock clock)
Set the clock to be used in tests.
|
TsidFactory.Builder |
withCustomEpoch(java.time.Instant customEpoch)
Set the custom epoch.
|
TsidFactory.Builder |
withNode(Integer node)
Set the node identifier.
|
TsidFactory.Builder |
withNodeBits(Integer nodeBits)
Set the node identifier bits length within the range 0 to 20.
|
TsidFactory.Builder |
withRandom(Random random)
Set the random generator.
|
TsidFactory.Builder |
withRandomFunction(java.util.function.IntFunction<byte[]> randomFunction)
Set the random function.
|
TsidFactory.Builder |
withRandomFunction(java.util.function.IntSupplier randomFunction)
Set the random function.
|
public TsidFactory.Builder withNode(Integer node)
The range is 0 to 2^nodeBits-1.
node - a number between 0 and 2^nodeBits-1.TsidFactory.Builderpublic TsidFactory.Builder withNodeBits(Integer nodeBits)
nodeBits - a number between 0 and 20.TsidFactory.Builderpublic TsidFactory.Builder withCustomEpoch(java.time.Instant customEpoch)
customEpoch - an instant that represents the custom epoch.TsidFactory.Builderpublic TsidFactory.Builder withRandom(Random random)
The random generator is used to create a random function that is used to reset the counter when the millisecond changes.
random - a Random generatorTsidFactory.Builderpublic TsidFactory.Builder withRandomFunction(java.util.function.IntSupplier randomFunction)
The random function is used to reset the counter when the millisecond changes.
randomFunction - a random function that returns a integer valueTsidFactory.Builderpublic TsidFactory.Builder withRandomFunction(java.util.function.IntFunction<byte[]> randomFunction)
The random function must return a byte array of a given length.
The random function is used to reset the counter when the millisecond changes.
Despite its name, the random function MAY return a fixed value, for example, if your app requires the counter to be reset to ZERO whenever the millisecond changes, like Twitter Snowflakes, this function should return an array filled with ZEROS.
If the returned value is NULL or EMPTY, the factory ignores it and just increments the counter when the millisecond changes, for example, when your app requires the counter to always be incremented, no matter if the millisecond has changed or not, like Discord Snowflakes.
randomFunction - a random function that returns a byte arrayTsidFactory.Builderpublic TsidFactory.Builder withClock(java.time.Clock clock)
clock - a clockTsidFactory.Builderpublic TsidFactory build()
TsidFactoryCopyright © 2024. All rights reserved.