Package com.fayupable.snowflake.config
Record Class SnowflakeConfig
java.lang.Object
java.lang.Record
com.fayupable.snowflake.config.SnowflakeConfig
public record SnowflakeConfig(long epoch, long nodeId, int timestampBits, int nodeBits, int sequenceBits)
extends Record
Configuration for the Snowflake id layout.
Bit layout (MSB to LSB): 1 unused sign bit | timestampBits | nodeBits | sequenceBits.
Default: 41-bit timestamp (~69 years from epoch), 10-bit node (up to 1024 nodes),
12-bit sequence (up to 4096 ids per millisecond per node).
-
Constructor Summary
ConstructorsConstructorDescriptionSnowflakeConfig(long epoch, long nodeId, int timestampBits, int nodeBits, int sequenceBits) Creates an instance of aSnowflakeConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic SnowflakeConfigdefaultConfig(long epoch, long nodeId) longepoch()Returns the value of theepochrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.longintnodeBits()Returns the value of thenodeBitsrecord component.longnodeId()Returns the value of thenodeIdrecord component.intintReturns the value of thesequenceBitsrecord component.intReturns the value of thetimestampBitsrecord component.intfinal StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SnowflakeConfig
public SnowflakeConfig(long epoch, long nodeId, int timestampBits, int nodeBits, int sequenceBits) Creates an instance of aSnowflakeConfigrecord class.- Parameters:
epoch- the value for theepochrecord componentnodeId- the value for thenodeIdrecord componenttimestampBits- the value for thetimestampBitsrecord componentnodeBits- the value for thenodeBitsrecord componentsequenceBits- the value for thesequenceBitsrecord component
-
-
Method Details
-
defaultConfig
-
maxSequence
public long maxSequence() -
nodeShift
public int nodeShift() -
timestampShift
public int timestampShift() -
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. -
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. -
equals
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 '=='. -
epoch
public long epoch()Returns the value of theepochrecord component.- Returns:
- the value of the
epochrecord component
-
nodeId
public long nodeId()Returns the value of thenodeIdrecord component.- Returns:
- the value of the
nodeIdrecord component
-
timestampBits
public int timestampBits()Returns the value of thetimestampBitsrecord component.- Returns:
- the value of the
timestampBitsrecord component
-
nodeBits
public int nodeBits()Returns the value of thenodeBitsrecord component.- Returns:
- the value of the
nodeBitsrecord component
-
sequenceBits
public int sequenceBits()Returns the value of thesequenceBitsrecord component.- Returns:
- the value of the
sequenceBitsrecord component
-