java.lang.Object
me.ahoo.cosid.IdGenerators
Small combinators that replace the 4.x generator classes of the same purpose (03-core-model.md ยง5).
-
Method Summary
Modifier and TypeMethodDescriptionstatic IdGeneratorlazy(Supplier<? extends IdGenerator> lookup) Looks the generator up on first use; replaces 4.xLazyIdGenerator.static IdGeneratorlocal()An in-process counter; replaces 4.xAtomicLongGenerator.static IntIdGeneratortoInt(IdGenerator ids) Narrows the ids ofidstoint; replaces 4.xIntegerIdGenerator.static IdGeneratoruncertain(IdGenerator ids, int bits, RandomGenerator random) Appendsbitsrandom low bits to each id; replaces 4.xUncertaintyIdGenerator.uuid()Random UUID text; replaces 4.xUuidGenerator.
-
Method Details
-
toInt
Narrows the ids ofidstoint; replaces 4.xIntegerIdGenerator.- Parameters:
ids- the generator- Returns:
- a generator that throws
IdOverflowExceptionfor an id beyondint
-
uncertain
Appendsbitsrandom low bits to each id; replaces 4.xUncertaintyIdGenerator.- Parameters:
ids- the generatorbits- the number of random low bitsrandom- the source of the random bits- Returns:
- the generator; it throws
IdOverflowExceptionfor a negative id or one that leaves no room for the bits
-
local
An in-process counter; replaces 4.xAtomicLongGenerator.- Returns:
- the generator
-
uuid
Random UUID text; replaces 4.xUuidGenerator.- Returns:
- the supplier
-
lazy
Looks the generator up on first use; replaces 4.xLazyIdGenerator.- Parameters:
lookup- supplies the generator- Returns:
- the generator
-