类 UlidFactory

java.lang.Object
cn.vonce.sql.uitls.UlidFactory

public final class UlidFactory extends Object
A class that actually generates ULIDs.

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

      public UlidFactory()
      Default constructor.
  • 方法详细资料

    • newInstance

      public static UlidFactory newInstance()
      Returns a new factory.

      It is equivalent to new UlidFactory().

      返回:
      UlidFactory
    • newInstance

      public static UlidFactory newInstance(Random random)
      Returns a new factory.
      参数:
      random - a Random generator
      返回:
      UlidFactory
    • newInstance

      public static UlidFactory newInstance(java.util.function.LongSupplier randomFunction)
      Returns a new factory.

      The given random function must return a long value.

      参数:
      randomFunction - a random function that returns a long value
      返回:
      UlidFactory
    • newInstance

      public static UlidFactory newInstance(java.util.function.IntFunction<byte[]> randomFunction)
      Returns a new factory.

      The given random function must return a byte array.

      参数:
      randomFunction - a random function that returns a byte array
      返回:
      UlidFactory
    • newMonotonicInstance

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

      public static UlidFactory newMonotonicInstance(Random random)
      Returns a new monotonic factory.
      参数:
      random - a Random generator
      返回:
      UlidFactory
    • newMonotonicInstance

      public static UlidFactory newMonotonicInstance(java.util.function.LongSupplier randomFunction)
      Returns a new monotonic factory.

      The given random function must return a long value.

      参数:
      randomFunction - a random function that returns a long value
      返回:
      UlidFactory
    • newMonotonicInstance

      public static UlidFactory newMonotonicInstance(java.util.function.IntFunction<byte[]> randomFunction)
      Returns a new monotonic factory.

      The given random function must return a byte array.

      参数:
      randomFunction - a random function that returns a byte array
      返回:
      UlidFactory
    • create

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

      public Ulid create(long time)
      Returns a UUID with a specific time.
      参数:
      time - a number of milliseconds since 1970-01-01 (Unix epoch).
      返回:
      a ULID