Class SnowflakeIdState

java.lang.Object
me.ahoo.cosid.snowflake.SnowflakeIdState
All Implemented Interfaces:
Comparable<SnowflakeIdState>

@Immutable public class SnowflakeIdState extends Object implements Comparable<SnowflakeIdState>
Immutable state object representing a parsed Snowflake ID.

This class holds the decomposed components of a Snowflake ID: the raw ID, machine ID, sequence number, timestamp, and a human-readable friendly format (timestamp-machineId-sequence).

  • Method Details

    • builder

      Creates a new builder for SnowflakeIdState.
      Returns:
      a new builder instance
    • getId

      public long getId()
      Gets the raw snowflake ID value.
      Returns:
      the raw 64-bit ID
    • getMachineId

      public int getMachineId()
      Gets the machine ID component.
      Returns:
      the machine ID
    • getSequence

      public long getSequence()
      Gets the sequence number component.
      Returns:
      the sequence number
    • getTimestamp

      public @NonNull LocalDateTime getTimestamp()
      Gets the timestamp when this ID was generated.
      Returns:
      the timestamp as LocalDateTime
    • getFriendlyId

      public @NonNull String getFriendlyId()
      Gets the human-readable form of this ID.
      Returns:
      friendly ID in format timestamp-machineId-sequence
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(SnowflakeIdState other)
      Compares this state to another by raw ID value.
      Specified by:
      compareTo in interface Comparable<SnowflakeIdState>
      Parameters:
      other - the other SnowflakeIdState to compare
      Returns:
      comparison result