Package me.ahoo.cosid.snowflake
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 timestampmachineBit- bits of the machine idsequenceBit- 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 Summary
ConstructorsConstructorDescriptionSnowflakeLayout(long epoch, int timestampBit, int machineBit, int sequenceBit) Validates the layout. -
Method Summary
Modifier and TypeMethodDescriptionlongepoch()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.booleanWhether every id fits in a JavaScript number without losing precision.intReturns the value of themachineBitrecord component.intLeft shift of the machine id: the sequence bits.intlonglongintReturns the value of thesequenceBitrecord component.intReturns the value of thetimestampBitrecord component.intLeft shift of the timestamp: the machine id and sequence bits.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SnowflakeLayout
public SnowflakeLayout(long epoch, int timestampBit, int machineBit, int sequenceBit) Validates the layout.- Throws:
IllegalArgumentException- if a bit count is negative,machineBitis 32 or more, or the total exceedsSnowflakeId.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
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
-
timestampBit
public int timestampBit()Returns the value of thetimestampBitrecord component.- Returns:
- the value of the
timestampBitrecord component
-
machineBit
public int machineBit()Returns the value of themachineBitrecord component.- Returns:
- the value of the
machineBitrecord component
-
sequenceBit
public int sequenceBit()Returns the value of thesequenceBitrecord component.- Returns:
- the value of the
sequenceBitrecord component
-