Class ObjectArrayEncoding<E>

Type Parameters:
E - array element type
All Implemented Interfaces:
Encoding<E[]>, NaturalSortAware, Serializable, Comparator<E[]>

public class ObjectArrayEncoding<E> extends ArrayEncoding<E[],E>
Array type for object arrays having non-primitive element types. Does not support null arrays.

In the binary encoding, array elements are simply concatenated, with each element preceded by a 0x01 byte. After the last element, a final 0x00 byte follows. This encoding ensures lexicographic ordering.

See Also:
  • Constructor Details

    • ObjectArrayEncoding

      public ObjectArrayEncoding(EncodingId encodingId, Encoding<E> elementEncoding)
  • Method Details

    • withEncodingId

      public ObjectArrayEncoding<E> withEncodingId(EncodingId encodingId)
      Description copied from interface: Encoding
      Build an encoding that has the given EncodingId but is otherwise equivalent to this encoding.

      If this encoding already has encodingId, then this method may (but is not required to) return this same instance.

      Parameters:
      encodingId - new encoding's EncodingId, or null for an anonymized encoding
      Returns:
      a version of this encoding with the given EncodingId
    • read

      public E[] read(ByteReader reader)
      Description copied from interface: Encoding
      Read a value from the given input.
      Parameters:
      reader - byte input
      Returns:
      field value (possibly null)
    • write

      public void write(ByteWriter writer, E[] array)
      Description copied from interface: Encoding
      Write a value to the given output.
      Parameters:
      writer - byte output
      array - value to write (possibly null)
    • skip

      public void skip(ByteReader reader)
      Description copied from interface: Encoding
      Read and discard a byte[] encoded value from the given input.
      Parameters:
      reader - byte input
    • getArrayLength

      protected int getArrayLength(E[] array)
      Description copied from class: ArrayEncoding
      Get the length of the given array.
      Specified by:
      getArrayLength in class ArrayEncoding<E[],E>
      Parameters:
      array - non-null array
      Returns:
      array length
    • getArrayElement

      protected E getArrayElement(E[] array, int index)
      Description copied from class: ArrayEncoding
      Get an element from the given array.
      Specified by:
      getArrayElement in class ArrayEncoding<E[],E>
      Parameters:
      array - non-null array
      index - index of target element in array
      Returns:
      array element at index index
    • createArray

      protected E[] createArray(List<E> elements)
      Description copied from class: ArrayEncoding
      Create a new array instance containing the given elements.
      Specified by:
      createArray in class ArrayEncoding<E[],E>
      Parameters:
      elements - content for the new array
      Returns:
      newly created array