Class SpanId


  • @Immutable
    public final class SpanId
    extends java.lang.Object
    Helper methods for dealing with a span identifier. A valid span identifier is a 16 character lowercase hex (base16) String, where at least one of the characters is not a "0".

    There are two more other representation that this class helps with:

    • Bytes: a 8-byte array, where valid means that at least one of the bytes is not `\0`.
    • Long: a long value, where valid means that the value is non-zero.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int BYTES_LENGTH  
      private static int HEX_LENGTH  
      private static java.lang.String INVALID  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SpanId()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String fromBytes​(byte[] spanIdBytes)
      Returns the lowercase hex (base16) representation of the SpanId converted from the given bytes representation, or getInvalid() if input is null or the given byte array is too short.
      static java.lang.String fromLong​(long id)
      Returns the lowercase hex (base16) representation of the SpanId converted from the given long value representation.
      static java.lang.String getInvalid()
      Returns the invalid SpanId in lowercase hex (base16) representation.
      static int getLength()
      Returns the length of the lowercase hex (base16) representation of the SpanId.
      static boolean isValid​(java.lang.CharSequence spanId)
      Returns whether the span identifier is valid.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SpanId

        private SpanId()
    • Method Detail

      • getLength

        public static int getLength()
        Returns the length of the lowercase hex (base16) representation of the SpanId.
        Returns:
        the length of the lowercase hex (base16) representation of the SpanId.
      • getInvalid

        public static java.lang.String getInvalid()
        Returns the invalid SpanId in lowercase hex (base16) representation. All characters are "0".
        Returns:
        the invalid SpanId lowercase in hex (base16) representation.
      • isValid

        public static boolean isValid​(java.lang.CharSequence spanId)
        Returns whether the span identifier is valid. A valid span identifier is a 16 character hex String, where at least one of the characters is not a '0'.
        Returns:
        true if the span identifier is valid.
      • fromBytes

        public static java.lang.String fromBytes​(byte[] spanIdBytes)
        Returns the lowercase hex (base16) representation of the SpanId converted from the given bytes representation, or getInvalid() if input is null or the given byte array is too short.

        It converts the first 8 bytes of the given byte array.

        Parameters:
        spanIdBytes - the bytes (8-byte array) representation of the SpanId.
        Returns:
        the lowercase hex (base16) representation of the SpanId.
      • fromLong

        public static java.lang.String fromLong​(long id)
        Returns the lowercase hex (base16) representation of the SpanId converted from the given long value representation.

        There is no restriction on the specified values, other than the already established validity rules applying to SpanId. Specifying 0 for the long value will effectively return getInvalid().

        This is equivalent to calling fromBytes(byte[]) with the specified value stored as big-endian.

        Parameters:
        id - long value representation of the SpanId.
        Returns:
        the lowercase hex (base16) representation of the SpanId.