Package com.github.nanoflakes
Class Nanoflakes
java.lang.Object
com.github.nanoflakes.Nanoflakes
Utility methods and constants related to Nanoflakes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic longHow much of an nanoflake is occupied by the generator ID, in bits.static longThe value used for generator id-based shifts.static longThe maximum ID possible for a generator.static longThe max sequence value of a snowflake.static longHow much of an nanoflake is occupied by sequence number, in bits.static longHow much of the nanoflake is occupied by the timestamp of the ID, in bits.static longThe value used for timestamp-based shifts. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longgeneratorValue(long id)Gets the generator ID of a nanoflake.static NanoflakeGeneratorlocalGenerator(long epoch, long generatorId)Creates a local generator.static longsequenceValue(long id)Gets the sequence ID of a nanoflake.static longtimestampValue(long id)Gets the timestamp of a nanoflake.static OffsetDateTimetoDateTime(long millis)Converts an UTC time in milliseconds to anOffsetDateTime.
-
Field Details
-
TIMESTAMP_BITS
public static final long TIMESTAMP_BITSHow much of the nanoflake is occupied by the timestamp of the ID, in bits.- See Also:
- Constant Field Values
-
GENERATOR_ID_BITS
public static final long GENERATOR_ID_BITSHow much of an nanoflake is occupied by the generator ID, in bits.- See Also:
- Constant Field Values
-
SEQUENCE_BITS
public static final long SEQUENCE_BITSHow much of an nanoflake is occupied by sequence number, in bits.- See Also:
- Constant Field Values
-
MAX_GENERATOR_ID
public static final long MAX_GENERATOR_IDThe maximum ID possible for a generator.- See Also:
- Constant Field Values
-
MAX_SEQUENCE
public static final long MAX_SEQUENCEThe max sequence value of a snowflake.- See Also:
- Constant Field Values
-
GENERATOR_ID_SHIFT
public static final long GENERATOR_ID_SHIFTThe value used for generator id-based shifts.- See Also:
- Constant Field Values
-
TIMESTAMP_SHIFT
public static final long TIMESTAMP_SHIFTThe value used for timestamp-based shifts.- See Also:
- Constant Field Values
-
-
Constructor Details
-
Nanoflakes
public Nanoflakes()
-
-
Method Details
-
localGenerator
Creates a local generator.- Parameters:
epoch- base epochgeneratorId- the generator id.- Returns:
- a new local nanoflake generator.
-
timestampValue
public static long timestampValue(long id)Gets the timestamp of a nanoflake.- Parameters:
id- the nanoflake.- Returns:
- the raw timestamp.
-
generatorValue
public static long generatorValue(long id)Gets the generator ID of a nanoflake.- Parameters:
id- the nanoflake.- Returns:
- the generator ID.
-
sequenceValue
public static long sequenceValue(long id)Gets the sequence ID of a nanoflake.- Parameters:
id- the nanoflake.- Returns:
- the sequence ID.
-
toDateTime
Converts an UTC time in milliseconds to anOffsetDateTime.- Parameters:
millis- UTC time, in milliseconds.- Returns:
- an instance of
OffsetDateTime.
-