Class Nanoflakes

java.lang.Object
com.github.nanoflakes.Nanoflakes

public class Nanoflakes extends Object
Utility methods and constants related to Nanoflakes.
  • Field Details

    • TIMESTAMP_BITS

      public static final long TIMESTAMP_BITS
      How much of the nanoflake is occupied by the timestamp of the ID, in bits.
      See Also:
      Constant Field Values
    • GENERATOR_ID_BITS

      public static final long GENERATOR_ID_BITS
      How much of an nanoflake is occupied by the generator ID, in bits.
      See Also:
      Constant Field Values
    • SEQUENCE_BITS

      public static final long SEQUENCE_BITS
      How much of an nanoflake is occupied by sequence number, in bits.
      See Also:
      Constant Field Values
    • MAX_GENERATOR_ID

      public static final long MAX_GENERATOR_ID
      The maximum ID possible for a generator.
      See Also:
      Constant Field Values
    • MAX_SEQUENCE

      public static final long MAX_SEQUENCE
      The max sequence value of a snowflake.
      See Also:
      Constant Field Values
    • GENERATOR_ID_SHIFT

      public static final long GENERATOR_ID_SHIFT
      The value used for generator id-based shifts.
      See Also:
      Constant Field Values
    • TIMESTAMP_SHIFT

      public static final long TIMESTAMP_SHIFT
      The value used for timestamp-based shifts.
      See Also:
      Constant Field Values
  • Constructor Details

    • Nanoflakes

      public Nanoflakes()
  • Method Details

    • localGenerator

      public static NanoflakeGenerator localGenerator(long epoch, long generatorId)
      Creates a local generator.
      Parameters:
      epoch - base epoch
      generatorId - the generator id.
      Returns:
      a new local nanoflake generator.
    • timestampValue

      public static long timestampValue(long id)
      Gets the timestamp of a nanoflake.
      Parameters:
      id - the nanoflake.
      Returns:
      the raw timestamp.
    • generatorValue

      public static long generatorValue(long id)
      Gets the generator ID of a nanoflake.
      Parameters:
      id - the nanoflake.
      Returns:
      the generator ID.
    • sequenceValue

      public static long sequenceValue(long id)
      Gets the sequence ID of a nanoflake.
      Parameters:
      id - the nanoflake.
      Returns:
      the sequence ID.
    • toDateTime

      public static OffsetDateTime toDateTime(long millis)
      Converts an UTC time in milliseconds to an OffsetDateTime.
      Parameters:
      millis - UTC time, in milliseconds.
      Returns:
      an instance of OffsetDateTime.