Class SpanId

  • All Implemented Interfaces:
    java.lang.Comparable<SpanId>

    @Immutable
    public final class SpanId
    extends java.lang.Object
    implements java.lang.Comparable<SpanId>
    A class that represents a span identifier. A valid span identifier is an 8-byte array with at least one non-zero byte.
    Since:
    0.5
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int BASE16_SIZE  
      private long id  
      static SpanId INVALID
      The invalid SpanId.
      private static long INVALID_ID  
      static int SIZE
      The size in bytes of the SpanId.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SpanId​(long id)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(SpanId that)  
      void copyBytesTo​(byte[] dest, int destOffset)
      Copies the byte array representations of the SpanId into the dest beginning at the destOffset offset.
      void copyLowerBase16To​(char[] dest, int destOffset)
      Copies the lowercase base16 representations of the SpanId into the dest beginning at the destOffset offset.
      boolean equals​(java.lang.Object obj)  
      static SpanId fromBytes​(byte[] src)
      Returns a SpanId built from a byte representation.
      static SpanId fromBytes​(byte[] src, int srcOffset)
      Returns a SpanId whose representation is copied from the src beginning at the srcOffset offset.
      static SpanId fromLowerBase16​(java.lang.CharSequence src)
      Returns a SpanId built from a lowercase base16 representation.
      static SpanId fromLowerBase16​(java.lang.CharSequence src, int srcOffset)
      Returns a SpanId built from a lowercase base16 representation.
      static SpanId generateRandomId​(java.util.Random random)
      Generates a new random SpanId.
      byte[] getBytes()
      Returns the byte representation of the SpanId.
      int hashCode()  
      boolean isValid()
      Returns whether the span identifier is valid.
      java.lang.String toLowerBase16()
      Returns the lowercase base16 encoding of this SpanId.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • SIZE

        public static final int SIZE
        The size in bytes of the SpanId.
        Since:
        0.5
        See Also:
        Constant Field Values
      • INVALID

        public static final SpanId INVALID
        The invalid SpanId. All bytes are 0.
        Since:
        0.5
      • id

        private final long id
    • Constructor Detail

      • SpanId

        private SpanId​(long id)
    • Method Detail

      • fromBytes

        public static SpanId fromBytes​(byte[] src)
        Returns a SpanId built from a byte representation.
        Parameters:
        src - the representation of the SpanId.
        Returns:
        a SpanId whose representation is given by the src parameter.
        Throws:
        java.lang.NullPointerException - if src is null.
        java.lang.IllegalArgumentException - if src.length is not SIZE.
        Since:
        0.5
      • fromBytes

        public static SpanId fromBytes​(byte[] src,
                                       int srcOffset)
        Returns a SpanId whose representation is copied from the src beginning at the srcOffset offset.
        Parameters:
        src - the buffer where the representation of the SpanId is copied.
        srcOffset - the offset in the buffer where the representation of the SpanId begins.
        Returns:
        a SpanId whose representation is copied from the buffer.
        Throws:
        java.lang.NullPointerException - if src is null.
        java.lang.IndexOutOfBoundsException - if srcOffset+SpanId.SIZE is greater than src.length.
        Since:
        0.5
      • fromLowerBase16

        public static SpanId fromLowerBase16​(java.lang.CharSequence src)
        Returns a SpanId built from a lowercase base16 representation.
        Parameters:
        src - the lowercase base16 representation.
        Returns:
        a SpanId built from a lowercase base16 representation.
        Throws:
        java.lang.NullPointerException - if src is null.
        java.lang.IllegalArgumentException - if src.length is not 2 * SpanId.SIZE OR if the str has invalid characters.
        Since:
        0.11
      • fromLowerBase16

        public static SpanId fromLowerBase16​(java.lang.CharSequence src,
                                             int srcOffset)
        Returns a SpanId built from a lowercase base16 representation.
        Parameters:
        src - the lowercase base16 representation.
        srcOffset - the offset in the buffer where the representation of the SpanId begins.
        Returns:
        a SpanId built from a lowercase base16 representation.
        Throws:
        java.lang.NullPointerException - if src is null.
        java.lang.IllegalArgumentException - if not enough characters in the src from the srcOffset.
        Since:
        0.11
      • generateRandomId

        public static SpanId generateRandomId​(java.util.Random random)
        Generates a new random SpanId.
        Parameters:
        random - The random number generator.
        Returns:
        a valid new SpanId.
        Since:
        0.5
      • getBytes

        public byte[] getBytes()
        Returns the byte representation of the SpanId.
        Returns:
        the byte representation of the SpanId.
        Since:
        0.5
      • copyBytesTo

        public void copyBytesTo​(byte[] dest,
                                int destOffset)
        Copies the byte array representations of the SpanId into the dest beginning at the destOffset offset.
        Parameters:
        dest - the destination buffer.
        destOffset - the starting offset in the destination buffer.
        Throws:
        java.lang.NullPointerException - if dest is null.
        java.lang.IndexOutOfBoundsException - if destOffset+SpanId.SIZE is greater than dest.length.
        Since:
        0.5
      • copyLowerBase16To

        public void copyLowerBase16To​(char[] dest,
                                      int destOffset)
        Copies the lowercase base16 representations of the SpanId into the dest beginning at the destOffset offset.
        Parameters:
        dest - the destination buffer.
        destOffset - the starting offset in the destination buffer.
        Throws:
        java.lang.IndexOutOfBoundsException - if destOffset + 2 * SpanId.SIZE is greater than dest.length.
        Since:
        0.18
      • isValid

        public boolean isValid()
        Returns whether the span identifier is valid. A valid span identifier is an 8-byte array with at least one non-zero byte.
        Returns:
        true if the span identifier is valid.
        Since:
        0.5
      • toLowerBase16

        public java.lang.String toLowerBase16()
        Returns the lowercase base16 encoding of this SpanId.
        Returns:
        the lowercase base16 encoding of this SpanId.
        Since:
        0.11
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(SpanId that)
        Specified by:
        compareTo in interface java.lang.Comparable<SpanId>