Class UlidFactory


  • public final class UlidFactory
    extends Object
    Factory that generates ULIDs. If the factory is not monotonic, the random component always changes. If the factory is monotonic, the random component changes whenever the millisecond changes. If more than one ULID is generated within the same millisecond, the random component is incremented by one. The maximum ULIDs that can be generated per millisecond is 2^80.
    • Constructor Detail

      • UlidFactory

        public UlidFactory()
    • Method Detail

      • newInstance

        public static UlidFactory newInstance()
        Returns a new factory. It is equivalent to new UlidFactory().
        Returns:
        UlidFactory
      • newInstance

        public static UlidFactory newInstance​(Supplier<byte[]> randomSupplier)
        Returns a new factory. The given random supplier must return an array of 10 bytes.
        Parameters:
        randomSupplier - a random supplier that returns 10 bytes
        Returns:
        UlidFactory
      • newMonotonicInstance

        public static UlidFactory newMonotonicInstance()
        Returns a new monotonic factory.
        Returns:
        UlidFactory
      • newMonotonicInstance

        public static UlidFactory newMonotonicInstance​(Random random)
        Returns a new monotonic factory.
        Parameters:
        random - a Random generator
        Returns:
        UlidFactory
      • newMonotonicInstance

        public static UlidFactory newMonotonicInstance​(Supplier<byte[]> randomSupplier)
        Returns a new monotonic factory. The given random supplier must return an array of 10 bytes.
        Parameters:
        randomSupplier - a random supplier that returns 10 bytes
        Returns:
        UlidFactory
      • create

        public Ulid create()
        Returns a UUID.
        Returns:
        a ULID
      • create

        public Ulid create​(long time)
        Returns a UUID with a specific time. The time must be the number of milliseconds since 1970-01-01 (Unix epoch).
        Parameters:
        time - a given time
        Returns:
        a ULID
      • getRandomSupplier

        protected static Supplier<byte[]> getRandomSupplier​(Random random)
        It instantiates a supplier that returns an array of 10 bytes.
        Parameters:
        random - a Random generator
        Returns:
        a random supplier that returns 10 bytes