类 Ulid
- 所有已实现的接口:
Serializable,Comparable<Ulid>
ULID is a 128-bit value that has two components:
- Time component: a number of milliseconds since 1970-01-01 (Unix epoch).
- Random component: a sequence of 80 random bits generated by a secure random generator.
ULID has 128-bit compatibility with UUID. Like a UUID, a ULID can
also be stored as a 16-byte array.
Instances of this class are immutable.
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明static final intNumber of bytes of the random component of a ULID.static final intNumber of characters of the random component of a ULID.static final intNumber of bytes of the time component of a ULID.static final intNumber of characters of the time component of a ULID.static final intNumber of bytes of a ULID.static final intNumber of characters of a ULID. -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明intCompares two ULIDs as unsigned 128-bit integers.booleanChecks if some other ULID is equal to this one.static Ulidfast()Returns a fast new ULID.static Ulidfrom(byte[] bytes) Converts a byte array into a ULID.static UlidConverts a canonical string into a ULID.static UlidConverts a UUID into a ULID.java.time.InstantReturns the instant of creation.static java.time.InstantgetInstant(String string) Returns the instant of creation.longReturns the least significant bits as a number.longReturns the most significant bits as a number.byte[]Returns the random component as a byte array.static byte[]Returns the random component as a byte array.longgetTime()Returns the time component as a number.static longReturns the time component as a number.inthashCode()Returns a hash code value for the ULID.Returns a new ULID by incrementing the random component of the current ULID.static booleanChecks if the input string is valid.byte[]toBytes()Convert the ULID into a byte array.Converts the ULID into a canonical string in lower case.Converts the ULID into into another ULID that is compatible with UUIDv4.toString()Converts the ULID into a canonical string in upper case.toUuid()Convert the ULID into a UUID.
-
字段详细资料
-
ULID_CHARS
public static final int ULID_CHARSNumber of characters of a ULID.- 另请参阅:
-
TIME_CHARS
public static final int TIME_CHARSNumber of characters of the time component of a ULID.- 另请参阅:
-
RANDOM_CHARS
public static final int RANDOM_CHARSNumber of characters of the random component of a ULID.- 另请参阅:
-
ULID_BYTES
public static final int ULID_BYTESNumber of bytes of a ULID.- 另请参阅:
-
TIME_BYTES
public static final int TIME_BYTESNumber of bytes of the time component of a ULID.- 另请参阅:
-
RANDOM_BYTES
public static final int RANDOM_BYTESNumber of bytes of the random component of a ULID.- 另请参阅:
-
-
构造器详细资料
-
Ulid
Creates a new ULID.Useful to make copies of ULIDs.
- 参数:
ulid- a ULID
-
Ulid
public Ulid(long mostSignificantBits, long leastSignificantBits) Creates a new ULID.If you want to make a copy of a
UUID, usefrom(UUID)instead.- 参数:
mostSignificantBits- the first 8 bytes as a long valueleastSignificantBits- the last 8 bytes as a long value
-
Ulid
public Ulid(long time, byte[] random) Creates a new ULID.Time parameter is the number of milliseconds since 1970-01-01 (Unix epoch). It must be a positive number not larger than 2^48-1.
Random parameter must be an array of 10 bytes.
- 参数:
time- the the number of milliseconds since 1970-01-01random- an array of 10 bytes- 抛出:
IllegalArgumentException- if time is negative or larger than 2^48-1IllegalArgumentException- if random is null or its length is not 10
-
-
方法详细资料
-
fast
Returns a fast new ULID.This static method is a quick alternative to
UlidCreator.getUlid().It employs
SplittableRandomwhich works very well, although not cryptographically strong.Security-sensitive applications that require a cryptographically secure pseudo-random generator should use
UlidCreator.getUlid().- 返回:
- a ULID
- 从以下版本开始:
- 5.1.0
-
from
Converts a UUID into a ULID.- 参数:
uuid- a UUID- 返回:
- a ULID
-
from
Converts a byte array into a ULID.- 参数:
bytes- an array of 16 bytes- 返回:
- a ULID
- 抛出:
IllegalArgumentException- if bytes are null or its length is not 16
-
from
Converts a canonical string into a ULID.The input string must be 26 characters long and must contain only characters from Crockford's base 32 alphabet.
The first character of the input string must be between 0 and 7.
- 参数:
string- a canonical string- 返回:
- a ULID
- 抛出:
IllegalArgumentException- if the input string is invalid- 另请参阅:
-
toUuid
Convert the ULID into a UUID.A ULID has 128-bit compatibility with a
UUID.If you need a RFC-4122 UUIDv4 do this:
Ulid.toRfc4122().toUuid().- 返回:
- a UUID.
-
toBytes
public byte[] toBytes()Convert the ULID into a byte array.- 返回:
- an byte array.
-
toString
Converts the ULID into a canonical string in upper case.The output string is 26 characters long and contains only characters from Crockford's Base 32 alphabet.
For lower case string, use the shorthand
Ulid#toLowerCase(), instead ofUlid#toString()#toLowerCase(). -
toLowerCase
Converts the ULID into a canonical string in lower case.The output string is 26 characters long and contains only characters from Crockford's Base 32 alphabet.
It is a shorthand at least twice as fast as
Ulid.toString().toLowerCase().- 返回:
- a string
- 另请参阅:
-
toRfc4122
Converts the ULID into into another ULID that is compatible with UUIDv4.The bytes of the returned ULID are compliant with the RFC-4122 version 4.
If you need a RFC-4122 UUIDv4 do this:
Ulid.toRfc4122().toUuid().Note: If you use this method, you can not get the original ULID, since it changes 6 bits of it to generate a UUIDv4.
- 返回:
- a ULID
- 另请参阅:
-
getInstant
public java.time.Instant getInstant()Returns the instant of creation.The instant of creation is extracted from the time component.
- 返回:
- the
Instantof creation
-
getInstant
Returns the instant of creation.The instant of creation is extracted from the time component.
- 参数:
string- a canonical string- 返回:
- the
Instantof creation - 抛出:
IllegalArgumentException- if the input string is invalid
-
getTime
public long getTime()Returns the time component as a number.The time component is a number between 0 and 2^48-1. It is equivalent to the count of milliseconds since 1970-01-01 (Unix epoch).
- 返回:
- a number of milliseconds
-
getTime
Returns the time component as a number.The time component is a number between 0 and 2^48-1. It is equivalent to the count of milliseconds since 1970-01-01 (Unix epoch).
- 参数:
string- a canonical string- 返回:
- a number of milliseconds
- 抛出:
IllegalArgumentException- if the input string is invalid
-
getRandom
public byte[] getRandom()Returns the random component as a byte array.The random component is an array of 10 bytes (80 bits).
- 返回:
- a byte array
-
getRandom
Returns the random component as a byte array.The random component is an array of 10 bytes (80 bits).
- 参数:
string- a canonical string- 返回:
- a byte array
- 抛出:
IllegalArgumentException- if the input string is invalid
-
getMostSignificantBits
public long getMostSignificantBits()Returns the most significant bits as a number.- 返回:
- a number.
-
getLeastSignificantBits
public long getLeastSignificantBits()Returns the least significant bits as a number.- 返回:
- a number.
-
increment
Returns a new ULID by incrementing the random component of the current ULID.Since the random component contains 80 bits:
- (1) This method can generate up to 1208925819614629174706176 (2^80) ULIDs per millisecond;
- (2) This method can generate monotonic increasing ULIDs 99.999999999999992% ((2^80 - 10^9) / (2^80)) of the time within a single millisecond interval, considering an unrealistic rate of 1,000,000,000 ULIDs per millisecond.
Due to (1) and (2), it does not throw the error message recommended by the specification. When an overflow occurs in the random 80 bits, the time component is simply incremented to maintain monotonicity.
- 返回:
- a ULID
-
isValid
Checks if the input string is valid.The input string must be 26 characters long and must contain only characters from Crockford's base 32 alphabet.
The first character of the input string must be between 0 and 7.
- 参数:
string- a canonical string- 返回:
- true if the input string is valid
- 另请参阅:
-
hashCode
public int hashCode()Returns a hash code value for the ULID. -
equals
Checks if some other ULID is equal to this one. -
compareTo
Compares two ULIDs as unsigned 128-bit integers.The first of two ULIDs is greater than the second if the most significant byte in which they differ is greater for the first ULID.
- 指定者:
compareTo在接口中Comparable<Ulid>- 参数:
that- a ULID to be compared with- 返回:
- -1, 0 or 1 as
thisis less than, equal to, or greater thanthat
-