Class BinVal

All Implemented Interfaces:
Comparable<BinVal>, HostResult

public class BinVal extends Val implements Comparable<BinVal>
A bin val, which represents an immutable array of bytes.

A bin val holds Java byte arrays as a binary tree in order to avoid allocation of the entire array on concatenation. The byte array is substantiated on demand.

  • Method Details

    • size

      public int size()
      Returns the size of the bin.
      Returns:
      the size of the bin.
    • bytes

      public byte[] bytes()
      Returns the copied bytes of the bin.
      Returns:
      the copied bytes of the bin.
    • copyToBytes

      public void copyToBytes(int from, int to, byte[] bytes, int at)
      Copy the range of this bin into bytes at the at index.
      Parameters:
      from - the inclusive start index.
      to - the exclusive end index.
      bytes - the destination bytes.
      at - the start index of the destination bytes.
    • get

      public byte get(int ind)
      Returns the byte at the ind.
      Parameters:
      ind - the index of the byte.
      Returns:
      the byte at the ind.
      Throws:
      IndexOutOfBoundsException - if ind is out of the range of the bin.
    • readOnlyByteBuffer

      public ByteBuffer readOnlyByteBuffer()
      Returns a read-only ByteBuffer of the content of this bin.

      The capacity of the result ByteBuffer is the size of the bin. The limit of the result ByteBuffer is set to the size of the bin. The position of the result ByteBuffer is set to 0.

      Returns:
      a read-only ByteBuffer of the content of this bin.
    • slice

      public BinVal slice(int from, int to)
      Returns a sliced bin between from (inclusive) and to (exclusive).
      Parameters:
      from - the inclusive index where the result is sliced from.
      to - the exclusive index where the result is sliced to.
      Returns:
      a sliced bin.
      Throws:
      IndexOutOfBoundsException - if from or to are out of the range of the bin.
      IllegalArgumentException - if from is larger than to.
    • compareTo

      public int compareTo(BinVal arg)
      Returns a negative number if this is less than arg, 0 if this is equivalent to arg, or a positive number if this is greater than arg.

      Comparison is done for the bytes of this and arg, treating the bytes as unsigned numbers.

      Comparison is agnostic with vm field.

      Specified by:
      compareTo in interface Comparable<BinVal>
      Parameters:
      arg - the arg bin to compare with.
      Returns:
      the comparison number.
    • concat

      public BinVal concat(BinVal tail)
      Returns a bin val which concatenates this and tail.
      Parameters:
      tail - the bin which is appended to the result.
      Returns:
      a bin val which concatenates this and tail.
    • equals

      public boolean equals(Object arg)
      Returns true if and only if arg is a bin val and has the same vm and the equivalent bytes with this.
      Overrides:
      equals in class Object
      Parameters:
      arg - the arg object to compare with.
      Returns:
      true if and only if arg is a bin val and has the same vm and the equivalent bytes with this.
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object