Package me.ahoo.cosid.snowflake
Class SecondSnowflakeIdStateParser
java.lang.Object
me.ahoo.cosid.snowflake.SnowflakeIdStateParser
me.ahoo.cosid.snowflake.SecondSnowflakeIdStateParser
Parser for second-based SnowflakeId state.
Handles conversion between second SnowflakeIds and their string
representations using format: yyyyMMddHHmmss-machineId-sequence.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DateTimeFormatterDateTimeFormatter for timestamps:yyyyMMddHHmmss.Fields inherited from class me.ahoo.cosid.snowflake.SnowflakeIdStateParser
DELIMITER, epoch, machineBit, machineLeft, machineMask, padStart, sequenceBit, sequenceMask, timestampBit, timestampLeft, timestampMask, zoneId -
Constructor Summary
ConstructorsConstructorDescriptionSecondSnowflakeIdStateParser(long epoch, int timestampBit, int machineBit, int sequenceBit) Creates a parser with default zone and no padding.SecondSnowflakeIdStateParser(long epoch, int timestampBit, int machineBit, int sequenceBit, ZoneId zoneId, boolean padStart) Creates a parser with custom zone and padding. -
Method Summary
Modifier and TypeMethodDescriptionprotected DateTimeFormatterGets the date time formatter for parsing timestamps.protected longgetDiffTime(LocalDateTime timestamp) Converts a LocalDateTime to time difference from epoch.protected LocalDateTimegetTimestamp(long diffTime) Converts a time difference to a LocalDateTime.static SecondSnowflakeIdStateParserof(SnowflakeId snowflakeId) static SecondSnowflakeIdStateParserof(SnowflakeId snowflakeId, ZoneId zoneId) static SecondSnowflakeIdStateParserof(SnowflakeId snowflakeId, ZoneId zoneId, boolean padStart) Methods inherited from class me.ahoo.cosid.snowflake.SnowflakeIdStateParser
getMachineCharSize, getSequenceCharSize, getZoneId, isPadStart, parse, parse, parseMachineId, parseSequence, parseTimestamp
-
Field Details
-
DATE_TIME_FORMATTER
DateTimeFormatter for timestamps:yyyyMMddHHmmss.
-
-
Constructor Details
-
SecondSnowflakeIdStateParser
public SecondSnowflakeIdStateParser(long epoch, int timestampBit, int machineBit, int sequenceBit) Creates a parser with default zone and no padding.- Parameters:
epoch- epoch timestamptimestampBit- bits for timestampmachineBit- bits for machine IDsequenceBit- bits for sequence
-
SecondSnowflakeIdStateParser
public SecondSnowflakeIdStateParser(long epoch, int timestampBit, int machineBit, int sequenceBit, ZoneId zoneId, boolean padStart) Creates a parser with custom zone and padding.- Parameters:
epoch- epoch timestamptimestampBit- bits for timestampmachineBit- bits for machine IDsequenceBit- bits for sequencezoneId- time zonepadStart- whether to pad
-
-
Method Details
-
getDateTimeFormatter
Description copied from class:SnowflakeIdStateParserGets the date time formatter for parsing timestamps.- Specified by:
getDateTimeFormatterin classSnowflakeIdStateParser- Returns:
- the date time formatter
-
getTimestamp
Description copied from class:SnowflakeIdStateParserConverts a time difference to a LocalDateTime.- Specified by:
getTimestampin classSnowflakeIdStateParser- Parameters:
diffTime- time difference from epoch in the appropriate unit- Returns:
- the corresponding LocalDateTime
-
getDiffTime
Description copied from class:SnowflakeIdStateParserConverts a LocalDateTime to time difference from epoch.- Specified by:
getDiffTimein classSnowflakeIdStateParser- Parameters:
timestamp- the LocalDateTime to convert- Returns:
- time difference from epoch
-
of
-
of
-
of
public static SecondSnowflakeIdStateParser of(SnowflakeId snowflakeId, ZoneId zoneId, boolean padStart)
-