Package me.ahoo.cosid

Class IdGenerators

java.lang.Object
me.ahoo.cosid.IdGenerators

public final class IdGenerators extends Object
Small combinators that replace the 4.x generator classes of the same purpose (03-core-model.md ยง5).
  • Method Details

    • toInt

      public static IntIdGenerator toInt(IdGenerator ids)
      Narrows the ids of ids to int; replaces 4.x IntegerIdGenerator.
      Parameters:
      ids - the generator
      Returns:
      a generator that throws IdOverflowException for an id beyond int
    • uncertain

      public static IdGenerator uncertain(IdGenerator ids, int bits, RandomGenerator random)
      Appends bits random low bits to each id; replaces 4.x UncertaintyIdGenerator.
      Parameters:
      ids - the generator
      bits - the number of random low bits
      random - the source of the random bits
      Returns:
      the generator; it throws IdOverflowException for a negative id or one that leaves no room for the bits
    • local

      public static IdGenerator local()
      An in-process counter; replaces 4.x AtomicLongGenerator.
      Returns:
      the generator
    • uuid

      public static Supplier<String> uuid()
      Random UUID text; replaces 4.x UuidGenerator.
      Returns:
      the supplier
    • lazy

      public static IdGenerator lazy(Supplier<? extends IdGenerator> lookup)
      Looks the generator up on first use; replaces 4.x LazyIdGenerator.
      Parameters:
      lookup - supplies the generator
      Returns:
      the generator