Package me.ahoo.cosid.snowflake
Class SnowflakeIdState
java.lang.Object
me.ahoo.cosid.snowflake.SnowflakeIdState
- All Implemented Interfaces:
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).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for SnowflakeIdState. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a new builder for SnowflakeIdState.intcompareTo(SnowflakeIdState other) Compares this state to another by raw ID value.boolean@NonNull StringGets the human-readable form of this ID.longgetId()Gets the raw snowflake ID value.intGets the machine ID component.longGets the sequence number component.@NonNull LocalDateTimeGets the timestamp when this ID was generated.inthashCode()toString()
-
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
Gets the timestamp when this ID was generated.- Returns:
- the timestamp as LocalDateTime
-
getFriendlyId
Gets the human-readable form of this ID.- Returns:
- friendly ID in format
timestamp-machineId-sequence
-
equals
-
hashCode
public int hashCode() -
toString
-
compareTo
Compares this state to another by raw ID value.- Specified by:
compareToin interfaceComparable<SnowflakeIdState>- Parameters:
other- the other SnowflakeIdState to compare- Returns:
- comparison result
-