Record Class SnowflakeLayout

java.lang.Object
java.lang.Record
me.ahoo.cosid.snowflake.SnowflakeLayout
Record Components:
epoch - the time the timestamp counts from, in the generator's time unit (milliseconds or seconds)
timestampBit - bits of the timestamp
machineBit - bits of the machine id
sequenceBit - bits of the sequence

public record SnowflakeLayout(long epoch, int timestampBit, int machineBit, int sequenceBit) extends Record
The bit layout of a snowflake id: timestamp | machine id | sequence, from the high bits to the low bits, with the timestamp counted from epoch.
Since:
4.0.0
  • Constructor Details

    • SnowflakeLayout

      public SnowflakeLayout(long epoch, int timestampBit, int machineBit, int sequenceBit)
      Validates the layout.
      Throws:
      IllegalArgumentException - if a bit count is negative, machineBit is 32 or more, or the total exceeds SnowflakeId.TOTAL_BIT
  • Method Details

    • maxTimestamp

      public long maxTimestamp()
    • maxMachineId

      public int maxMachineId()
    • maxSequence

      public long maxSequence()
    • machineLeft

      public int machineLeft()
      Left shift of the machine id: the sequence bits.
    • timestampLeft

      public int timestampLeft()
      Left shift of the timestamp: the machine id and sequence bits.
    • isSafeJavascript

      public boolean isSafeJavascript()
      Whether every id fits in a JavaScript number without losing precision.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • epoch

      public long epoch()
      Returns the value of the epoch record component.
      Returns:
      the value of the epoch record component
    • timestampBit

      public int timestampBit()
      Returns the value of the timestampBit record component.
      Returns:
      the value of the timestampBit record component
    • machineBit

      public int machineBit()
      Returns the value of the machineBit record component.
      Returns:
      the value of the machineBit record component
    • sequenceBit

      public int sequenceBit()
      Returns the value of the sequenceBit record component.
      Returns:
      the value of the sequenceBit record component