public final class Ksuid extends Object implements Serializable, Comparable<Ksuid>
KSUID is a 160-bit value that has two parts:
Instances of this class are immutable.
| 限定符和类型 | 字段和说明 |
|---|---|
static long |
EPOCH_OFFSET
Number of seconds of 2014-05-13T16:53:20Z (14e8).
|
static int |
KSUID_BYTES
Number of bytes of a KSUID.
|
static int |
KSUID_CHARS
Number of characters of a KSUID.
|
static int |
PAYLOAD_BYTES
Number of bytes of the payload of a KSUID.
|
static int |
TIME_BYTES
Number of bytes of the time of a KSUID.
|
| 构造器和说明 |
|---|
Ksuid(Ksuid ksuid)
Creates a new KSUID.
|
Ksuid(long seconds,
byte[] payload)
Creates a new KSUID.
|
| 限定符和类型 | 方法和说明 |
|---|---|
int |
compareTo(Ksuid that)
Compares two KSUIDs as unsigned 160-bit integers.
|
boolean |
equals(Object other)
Checks if some other KSUID is equal to this one.
|
static Ksuid |
from(byte[] bytes)
Convert a byte array into a KSUID.
|
static Ksuid |
from(String string)
Convert a canonical string into a KSUID.
|
java.time.Instant |
getInstant()
Return the instant of creation.
|
static java.time.Instant |
getInstant(String string)
Return the instant of creation.
|
byte[] |
getPayload()
Return the payload.
|
static byte[] |
getPayload(String string)
Return the payload.
|
long |
getTime()
Return the creation time.
|
static long |
getTime(String string)
Return the creation time.
|
int |
hashCode()
Returns a hash code value for the KSUID.
|
Ksuid |
increment()
Returns a new KSUID by incrementing the payload of the current KSUID.
|
static boolean |
isValid(String string)
Check if the input string is valid.
|
byte[] |
toBytes()
Convert the KSUID into a byte array.
|
String |
toString()
Convert the KSUID into a canonical string.
|
public static final int KSUID_CHARS
public static final int KSUID_BYTES
public static final int TIME_BYTES
public static final int PAYLOAD_BYTES
public static final long EPOCH_OFFSET
public Ksuid(Ksuid ksuid)
Useful to make copies of KSUIDs.
ksuid - a KSUIDpublic Ksuid(long seconds,
byte[] payload)
Seconds parameter is the number of seconds since 1970-01-01 (Unix epoch). It is internally converted to KSUID time.
Payload parameter must be an array of 16 bytes.
seconds - the number of seconds since 1970-01-01payload - an array of 16 bytesIllegalArgumentException - if payload is null or its length is not 16public static Ksuid from(byte[] bytes)
bytes - an array of 20 bytesIllegalArgumentException - if bytes are null or its length is not 20public static Ksuid from(String string)
The input string must be 27 characters long and must contain only characters from base-62 alphabet.
string - a canonical stringIllegalArgumentException - if the input string is invalidpublic static java.time.Instant getInstant(String string)
The instant of creation is extracted from the creation time.
string - a canonical stringInstant of creationIllegalArgumentException - if the input string is invalidpublic static long getTime(String string)
The number returned is equivalent to the number of seconds since 1970-01-01 (Unix epoch).
string - a canonical stringIllegalArgumentException - if the input string is invalidpublic static byte[] getPayload(String string)
The payload is an array of 16 bytes (128 bits).
string - a canonical stringpublic static boolean isValid(String string)
The input string must be 27 characters long and must contain only characters from base-62 alphabet.
string - a canonical stringpublic byte[] toBytes()
public String toString()
The output string is 27 characters long and contains only characters from base-62 alphabet.
toString 在类中 Objectpublic java.time.Instant getInstant()
The instant of creation is extracted from the creation time.
Instant of creationpublic long getTime()
The number returned is equivalent to the number of seconds since 1970-01-01 (Unix epoch).
public byte[] getPayload()
The payload is an array of 16 bytes (128 bits).
public boolean equals(Object other)
public int compareTo(Ksuid that)
The first of two KSUID is greater than the second if the most significant byte in which they differ is greater for the first KSUID.
compareTo 在接口中 Comparable<Ksuid>that - a KSUID to be compared withthis is less than, equal to, or greater than
thatpublic Ksuid increment()
When an overflow occurs in the payload 128 bits, the time is simply incremented to maintain monotonicity.
Copyright © 2024. All rights reserved.