@Immutable public final class TraceId extends Object implements Comparable<TraceId>
Modifier and Type | Field and Description |
---|---|
static TraceId |
INVALID
The invalid
TraceId . |
static int |
SIZE
The size in bytes of the
TraceId . |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(TraceId that) |
void |
copyBytesTo(byte[] dest,
int destOffset)
Copies the byte array representations of the
TraceId into the dest beginning at
the destOffset offset. |
void |
copyLowerBase16To(char[] dest,
int destOffset)
Copies the lowercase base16 representations of the
TraceId into the dest
beginning at the destOffset offset. |
boolean |
equals(Object obj) |
static TraceId |
fromBytes(byte[] src)
Returns a
TraceId built from a byte representation. |
static TraceId |
fromBytes(byte[] src,
int srcOffset)
Returns a
TraceId whose representation is copied from the src beginning at the
srcOffset offset. |
static TraceId |
fromLowerBase16(CharSequence src)
Returns a
TraceId built from a lowercase base16 representation. |
static TraceId |
fromLowerBase16(CharSequence src,
int srcOffset)
Returns a
TraceId built from a lowercase base16 representation. |
static TraceId |
generateRandomId(Random random)
Generates a new random
TraceId . |
byte[] |
getBytes()
Returns the 16-bytes array representation of the
TraceId . |
long |
getLowerLong()
Returns the lower 8 bytes of the trace-id as a long value, assuming little-endian order.
|
int |
hashCode() |
boolean |
isValid()
Returns whether the
TraceId is valid. |
String |
toLowerBase16()
Returns the lowercase base16 encoding of this
TraceId . |
String |
toString() |
public static final int SIZE
TraceId
.public static final TraceId INVALID
TraceId
. All bytes are '\0'.public static TraceId fromBytes(byte[] src)
TraceId
built from a byte representation.src
- the representation of the TraceId
.TraceId
whose representation is given by the src
parameter.NullPointerException
- if src
is null.IllegalArgumentException
- if src.length
is not SIZE
.public static TraceId fromBytes(byte[] src, int srcOffset)
TraceId
whose representation is copied from the src
beginning at the
srcOffset
offset.src
- the buffer where the representation of the TraceId
is copied.srcOffset
- the offset in the buffer where the representation of the TraceId
begins.TraceId
whose representation is copied from the buffer.NullPointerException
- if src
is null.IndexOutOfBoundsException
- if srcOffset+TraceId.SIZE
is greater than src.length
.public static TraceId fromLowerBase16(CharSequence src)
TraceId
built from a lowercase base16 representation.src
- the lowercase base16 representation.TraceId
built from a lowercase base16 representation.NullPointerException
- if src
is null.IllegalArgumentException
- if src.length
is not 2 * TraceId.SIZE
OR if
the str
has invalid characters.public static TraceId fromLowerBase16(CharSequence src, int srcOffset)
TraceId
built from a lowercase base16 representation.src
- the lowercase base16 representation.srcOffset
- the offset in the buffer where the representation of the TraceId
begins.TraceId
built from a lowercase base16 representation.NullPointerException
- if src
is null.IllegalArgumentException
- if not enough characters in the src
from the srcOffset
.public static TraceId generateRandomId(Random random)
TraceId
.random
- the random number generator.TraceId
.public byte[] getBytes()
TraceId
.TraceId
.public void copyBytesTo(byte[] dest, int destOffset)
TraceId
into the dest
beginning at
the destOffset
offset.dest
- the destination buffer.destOffset
- the starting offset in the destination buffer.NullPointerException
- if dest
is null.IndexOutOfBoundsException
- if destOffset+TraceId.SIZE
is greater than dest.length
.public void copyLowerBase16To(char[] dest, int destOffset)
TraceId
into the dest
beginning at the destOffset
offset.dest
- the destination buffer.destOffset
- the starting offset in the destination buffer.IndexOutOfBoundsException
- if destOffset + 2 * TraceId.SIZE
is greater than
dest.length
.public boolean isValid()
TraceId
is valid. A valid trace identifier is a 16-byte array with
at least one non-zero byte.true
if the TraceId
is valid.public String toLowerBase16()
TraceId
.TraceId
.@Internal public long getLowerLong()
This method is marked as internal and subject to change.
public int compareTo(TraceId that)
compareTo
in interface Comparable<TraceId>