Package com.codahale.timeid
Class IdGenerator
- java.lang.Object
-
- com.codahale.timeid.IdGenerator
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable
public class IdGenerator extends java.lang.Object implements java.io.ExternalizableIdGeneratorgenerates 27-character, time-ordered, k-sortable, URL-safe, globally unique identifiers.The identifiers are encoded with Radix-64, using an alphabet which is both URL-safe and which preserves lexical ordering. Each ID consists of a 32-bit, big-endian timestamp (the number of seconds since 1.4e9 seconds after the Unix epoch), plus 128 bits of random data.
Random data is produced via ChaCha20 in a fast-key-erasure construction.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description IdGenerator()Creates a newIdGenerator.
-
Method Summary
Modifier and Type Method Description static java.time.InstantcreatedAt(java.lang.String id)Returns theInstantat which the ID was created.java.lang.Stringgenerate()Generates a new ID.voidreadExternal(java.io.ObjectInput in)voidwriteExternal(java.io.ObjectOutput out)
-
-
-
Field Detail
-
MIN_VALUE
public static final java.lang.String MIN_VALUE
Lexically, the first possible ID.- See Also:
- Constant Field Values
-
MAX_VALUE
public static final java.lang.String MAX_VALUE
Lexically, the last possible ID.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
IdGenerator
public IdGenerator()
Creates a newIdGenerator.
-
-
Method Detail
-
generate
public java.lang.String generate()
Generates a new ID.- Returns:
- a new 27-character ID
-
createdAt
public static java.time.Instant createdAt(java.lang.String id)
Returns theInstantat which the ID was created.- Parameters:
id- a time ID- Returns:
- the ID's timestamp
-
writeExternal
public void writeExternal(java.io.ObjectOutput out)
- Specified by:
writeExternalin interfacejava.io.Externalizable
-
readExternal
public void readExternal(java.io.ObjectInput in)
- Specified by:
readExternalin interfacejava.io.Externalizable
-
-