Class AbstractByteRange

java.lang.Object
org.apache.hadoop.hbase.util.AbstractByteRange
All Implemented Interfaces:
Comparable<ByteRange>, ByteRange
Direct Known Subclasses:
AbstractPositionedByteRange, SimpleByteRange, SimpleMutableByteRange

@Private @Evolving public abstract class AbstractByteRange extends Object implements ByteRange
An abstract implementation of the ByteRange API
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected byte[]
    The array containing the bytes in this range.
    protected int
    Variable for lazy-caching the hashCode of this range.
    protected int
    The number of bytes in the range.
    protected int
    The index of the first byte in this range.
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    int
    Bitwise comparison of each byte in the array.
    void
    deepCopySubRangeTo(int innerOffset, int copyLength, byte[] destination, int destinationOffset)
    Wrapper for System.arraycopy.
    void
    deepCopyTo(byte[] destination, int destinationOffset)
    Wrapper for System.arraycopy.
    byte[]
    Instantiate a new byte[] with exact length, which is at least 24 bytes + length.
    boolean
     
    byte
    get(int index)
    Retrieve the byte at index.
    get(int index, byte[] dst)
    Fill dst with bytes from the range, starting from index.
    get(int index, byte[] dst, int offset, int length)
    Fill dst with bytes from the range, starting from index.
    byte[]
    The underlying byte[].
    int
    getInt(int index)
    Retrieve the int value at index
    int
    The length of the range.
    long
    getLong(int index)
    Retrieve the long value at index
    int
    The offset, the index into the underlying byte[] at which this range begins.
    short
    getShort(int index)
    Retrieve the short value at index
    long
    getVLong(int index)
    Retrieve the long value at index which is stored as VLong
    static int
    getVLongSize(long val)
     
    int
     
    boolean
    Returns true when this range is of zero length, false otherwise.
    static boolean
    Returns true when range is of zero length, false otherwise.
    protected boolean
     
    set(byte[] bytes)
    Reuse this ByteRange over a new byte[].
    set(byte[] bytes, int offset, int length)
    Reuse this ByteRange over a new byte[].
    set(int capacity)
    Reuse this ByteRange over a new byte[].
    setLength(int length)
    Update the length of this range.
    setOffset(int offset)
    Update the beginning of this range.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.hadoop.hbase.util.ByteRange

    deepCopy, put, put, put, putInt, putLong, putShort, putVLong, shallowCopy, shallowCopySubRange, unset
  • Field Details

    • UNSET_HASH_VALUE

      public static final int UNSET_HASH_VALUE
      See Also:
    • bytes

      protected byte[] bytes
      The array containing the bytes in this range. It will be >= length.
    • offset

      protected int offset
      The index of the first byte in this range. ByteRange.get(0) will return bytes[offset].
    • length

      protected int length
      The number of bytes in the range. Offset + length must be <= bytes.length
    • hash

      protected int hash
      Variable for lazy-caching the hashCode of this range. Useful for frequently used ranges, long-lived ranges, or long ranges.
  • Constructor Details

  • Method Details

    • getBytes

      public byte[] getBytes()
      Description copied from interface: ByteRange
      The underlying byte[].
      Specified by:
      getBytes in interface ByteRange
    • set

      public ByteRange set(int capacity)
      Description copied from interface: ByteRange
      Reuse this ByteRange over a new byte[]. offset is set to 0 and length is set to capacity.
      Specified by:
      set in interface ByteRange
      Parameters:
      capacity - the size of a new byte[].
    • set

      public ByteRange set(byte[] bytes)
      Description copied from interface: ByteRange
      Reuse this ByteRange over a new byte[]. offset is set to 0 and length is set to bytes.length. A null bytes IS supported, in which case this method will behave equivalently to ByteRange.unset().
      Specified by:
      set in interface ByteRange
      Parameters:
      bytes - the array to wrap.
    • set

      public ByteRange set(byte[] bytes, int offset, int length)
      Description copied from interface: ByteRange
      Reuse this ByteRange over a new byte[]. A null bytes IS supported, in which case this method will behave equivalently to ByteRange.unset(), regardless of the values of offset and length.
      Specified by:
      set in interface ByteRange
      Parameters:
      bytes - The array to wrap.
      offset - The offset into bytes considered the beginning of this range.
      length - The length of this range.
      Returns:
      this.
    • getOffset

      public int getOffset()
      Description copied from interface: ByteRange
      The offset, the index into the underlying byte[] at which this range begins.
      Specified by:
      getOffset in interface ByteRange
      See Also:
    • setOffset

      public ByteRange setOffset(int offset)
      Description copied from interface: ByteRange
      Update the beginning of this range. offset + length may not be greater than bytes.length.
      Specified by:
      setOffset in interface ByteRange
      Parameters:
      offset - the new start of this range.
      Returns:
      this.
    • getLength

      public int getLength()
      Description copied from interface: ByteRange
      The length of the range.
      Specified by:
      getLength in interface ByteRange
    • setLength

      public ByteRange setLength(int length)
      Description copied from interface: ByteRange
      Update the length of this range. offset + length should not be greater than bytes.length.
      Specified by:
      setLength in interface ByteRange
      Parameters:
      length - The new length of this range.
      Returns:
      this.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: ByteRange
      Returns true when this range is of zero length, false otherwise.
      Specified by:
      isEmpty in interface ByteRange
    • isEmpty

      public static boolean isEmpty(ByteRange range)
      Returns true when range is of zero length, false otherwise.
    • get

      public byte get(int index)
      Description copied from interface: ByteRange
      Retrieve the byte at index.
      Specified by:
      get in interface ByteRange
      Parameters:
      index - zero-based index into this range.
      Returns:
      single byte at index.
    • get

      public ByteRange get(int index, byte[] dst)
      Description copied from interface: ByteRange
      Fill dst with bytes from the range, starting from index.
      Specified by:
      get in interface ByteRange
      Parameters:
      index - zero-based index into this range.
      dst - the destination of the copy.
      Returns:
      this.
    • get

      public ByteRange get(int index, byte[] dst, int offset, int length)
      Description copied from interface: ByteRange
      Fill dst with bytes from the range, starting from index. length bytes are copied into dst, starting at offset.
      Specified by:
      get in interface ByteRange
      Parameters:
      index - zero-based index into this range.
      dst - the destination of the copy.
      offset - the offset into dst to start the copy.
      length - the number of bytes to copy into dst.
      Returns:
      this.
    • getShort

      public short getShort(int index)
      Description copied from interface: ByteRange
      Retrieve the short value at index
      Specified by:
      getShort in interface ByteRange
      Parameters:
      index - zero-based index into this range
      Returns:
      the short value at index
    • getInt

      public int getInt(int index)
      Description copied from interface: ByteRange
      Retrieve the int value at index
      Specified by:
      getInt in interface ByteRange
      Parameters:
      index - zero-based index into this range
      Returns:
      the int value at index
    • getLong

      public long getLong(int index)
      Description copied from interface: ByteRange
      Retrieve the long value at index
      Specified by:
      getLong in interface ByteRange
      Parameters:
      index - zero-based index into this range
      Returns:
      the long value at index
    • getVLong

      public long getVLong(int index)
      Description copied from interface: ByteRange
      Retrieve the long value at index which is stored as VLong
      Specified by:
      getVLong in interface ByteRange
      Parameters:
      index - zero-based index into this range
      Returns:
      the long value at index which is stored as VLong
    • getVLongSize

      public static int getVLongSize(long val)
    • deepCopyToNewArray

      public byte[] deepCopyToNewArray()
      Description copied from interface: ByteRange
      Instantiate a new byte[] with exact length, which is at least 24 bytes + length. Copy the contents of this range into it.
      Specified by:
      deepCopyToNewArray in interface ByteRange
      Returns:
      The newly cloned byte[].
    • deepCopyTo

      public void deepCopyTo(byte[] destination, int destinationOffset)
      Description copied from interface: ByteRange
      Wrapper for System.arraycopy. Copy the contents of this range into the provided array.
      Specified by:
      deepCopyTo in interface ByteRange
      Parameters:
      destination - Copy to this array
      destinationOffset - First index in the destination array.
    • deepCopySubRangeTo

      public void deepCopySubRangeTo(int innerOffset, int copyLength, byte[] destination, int destinationOffset)
      Description copied from interface: ByteRange
      Wrapper for System.arraycopy. Copy the contents of this range into the provided array.
      Specified by:
      deepCopySubRangeTo in interface ByteRange
      Parameters:
      innerOffset - Start copying from this index in this source ByteRange. First byte copied is bytes[offset + innerOffset]
      copyLength - Copy this many bytes
      destination - Copy to this array
      destinationOffset - First index in the destination array.
    • hashCode

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

      protected boolean isHashCached()
    • clearHashCache

      protected void clearHashCache()
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(ByteRange other)
      Bitwise comparison of each byte in the array. Unsigned comparison, not paying attention to java's signed bytes.
      Specified by:
      compareTo in interface Comparable<ByteRange>
    • toString

      public String toString()
      Overrides:
      toString in class Object