public final class Xid extends Object implements Comparable<Xid>
A globally unique identifier for objects.
Consists of 12 bytes, divided as follows:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| time | random value | inc | |||||||||
Instances of this class are immutable.
| 构造器和说明 |
|---|
Xid()
Create a new object id.
|
Xid(byte[] bytes)
Constructs a new instance from the given byte array
|
Xid(ByteBuffer buffer)
Constructs a new instance from the given ByteBuffer
|
Xid(Date date)
Constructs a new instance using the given date.
|
Xid(Date date,
int counter)
Constructs a new instances using the given date and counter.
|
Xid(int timestamp,
int counter)
Creates an Xid using the given time, machine identifier, process identifier, and counter.
|
Xid(String hexString)
Constructs a new instance from a 24-byte hexadecimal string representation.
|
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
bytes() |
int |
compareTo(Xid other) |
boolean |
equals(Object o) |
static Xid |
get()
Gets a new object id.
|
Date |
getDate()
Gets the timestamp as a
Date instance. |
static Xid |
getSmallestWithDate(Date date)
Gets a new object id with the given date value and all other bits zeroed.
|
int |
getTimestamp()
Gets the timestamp (number of seconds since the Unix epoch).
|
int |
hashCode() |
static void |
isTrue(String name,
boolean condition) |
static boolean |
isValid(String hexString)
Checks if a string could be an
Xid. |
void |
putToByteBuffer(ByteBuffer buffer)
Convert to bytes and put those bytes to the provided ByteBuffer.
|
static String |
string() |
byte[] |
toByteArray()
Convert to a byte array.
|
String |
toHexString()
Converts this instance into a 20-byte hexadecimal string representation.
|
String |
toString() |
public Xid()
public Xid(Date date)
date - the datepublic Xid(Date date, int counter)
date - the datecounter - the counterIllegalArgumentException - if the high order byte of counter is not zeropublic Xid(int timestamp,
int counter)
timestamp - the time in secondscounter - the counterIllegalArgumentException - if the high order byte of counter is not zeropublic Xid(String hexString)
hexString - the string to convertIllegalArgumentException - if the string is not a valid hex string representation of an Xidpublic Xid(byte[] bytes)
bytes - the byte arrayIllegalArgumentException - if array is null or not of length 12public Xid(ByteBuffer buffer)
buffer - the ByteBufferIllegalArgumentException - if the buffer is null or does not have at least 12 bytes remainingpublic static Xid get()
public static String string()
public static byte[] bytes()
public static Xid getSmallestWithDate(Date date)
The returned object id will compare as less than or equal to any other object id within the same second as the given date, and less than any later date.
date - the datepublic byte[] toByteArray()
public void putToByteBuffer(ByteBuffer buffer)
buffer - the ByteBufferIllegalArgumentException - if the buffer is null or does not have at least 12 bytes remainingpublic int getTimestamp()
public Date getDate()
Date instance.public String toHexString()
public int compareTo(Xid other)
compareTo 在接口中 Comparable<Xid>public static boolean isValid(String hexString)
Xid.hexString - a potential Xid as a String.IllegalArgumentException - if hexString is nullpublic static void isTrue(String name, boolean condition)
Copyright © 2022. All rights reserved.