Class AbstractPositionedByteRange

java.lang.Object
com.mapr.org.apache.hadoop.hbase.util.AbstractByteRange
com.mapr.org.apache.hadoop.hbase.util.AbstractPositionedByteRange
All Implemented Interfaces:
ByteRange, PositionedByteRange, Comparable<ByteRange>
Direct Known Subclasses:
SimplePositionedByteRange, SimplePositionedMutableByteRange

public abstract class AbstractPositionedByteRange extends AbstractByteRange implements PositionedByteRange
Extends the basic SimpleByteRange implementation with position support. position is considered transient, not fundamental to the definition of the range, and does not participate in AbstractByteRange.compareTo(ByteRange), AbstractByteRange.hashCode(), or Object.equals(Object). Position is retained by copy operations.
  • Field Details

    • position

      protected int position
      The current index into the range. Like ByteBuffer position, it points to the next value that will be read/written in the array. It provides the appearance of being 0-indexed, even though its value is calculated according to offset.

      Position is considered transient and does not participate in Object.equals(Object) or AbstractByteRange.hashCode() comparisons.

    • limit

      protected int limit
  • Constructor Details

    • AbstractPositionedByteRange

      public AbstractPositionedByteRange()
  • Method Details

    • unset

      public abstract PositionedByteRange unset()
      Description copied from interface: ByteRange
      Nullifies this ByteRange. That is, it becomes a husk, being a range over no byte[] whatsoever.
      Specified by:
      unset in interface ByteRange
      Specified by:
      unset in interface PositionedByteRange
      Specified by:
      unset in class AbstractByteRange
      Returns:
      this
    • set

      public PositionedByteRange 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
      Specified by:
      set in interface PositionedByteRange
      Overrides:
      set in class AbstractByteRange
      Parameters:
      capacity - the size of a new byte[].
      Returns:
      this
    • set

      public PositionedByteRange 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
      Specified by:
      set in interface PositionedByteRange
      Overrides:
      set in class AbstractByteRange
      Parameters:
      bytes - the array to wrap.
      Returns:
      this
    • set

      public PositionedByteRange 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
      Specified by:
      set in interface PositionedByteRange
      Overrides:
      set in class AbstractByteRange
      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.
    • setOffset

      public PositionedByteRange setOffset(int offset)
      Update the beginning of this range. offset + length may not be greater than bytes.length. Resets position to 0.
      Specified by:
      setOffset in interface ByteRange
      Specified by:
      setOffset in interface PositionedByteRange
      Overrides:
      setOffset in class AbstractByteRange
      Parameters:
      offset - the new start of this range.
      Returns:
      this.
    • setLength

      public PositionedByteRange setLength(int length)
      Update the length of this range. offset + length should not be greater than bytes.length. If position is greater than the new length, sets position to length.
      Specified by:
      setLength in interface ByteRange
      Specified by:
      setLength in interface PositionedByteRange
      Overrides:
      setLength in class AbstractByteRange
      Parameters:
      length - The new length of this range.
      Returns:
      this.
    • getPosition

      public int getPosition()
      Description copied from interface: PositionedByteRange
      The current position marker. This valuae is 0-indexed, relative to the beginning of the range.
      Specified by:
      getPosition in interface PositionedByteRange
    • setPosition

      public PositionedByteRange setPosition(int position)
      Description copied from interface: PositionedByteRange
      Update the position index. May not be greater than length.
      Specified by:
      setPosition in interface PositionedByteRange
      Parameters:
      position - the new position in this range.
      Returns:
      this.
    • getRemaining

      public int getRemaining()
      Description copied from interface: PositionedByteRange
      The number of bytes remaining between position and the end of the range.
      Specified by:
      getRemaining in interface PositionedByteRange
    • peek

      public byte peek()
      Description copied from interface: PositionedByteRange
      Retrieve the next byte from this range without incrementing position.
      Specified by:
      peek in interface PositionedByteRange
    • get

      public byte get()
      Description copied from interface: PositionedByteRange
      Retrieve the next byte from this range.
      Specified by:
      get in interface PositionedByteRange
    • get

      public PositionedByteRange get(byte[] dst)
      Description copied from interface: PositionedByteRange
      Fill dst with bytes from the range, starting from position. This range's position is incremented by the length of dst, the number of bytes copied.
      Specified by:
      get in interface PositionedByteRange
      Parameters:
      dst - the destination of the copy.
      Returns:
      this.
    • get

      public PositionedByteRange get(byte[] dst, int offset, int length)
      Description copied from interface: PositionedByteRange
      Fill dst with bytes from the range, starting from the current position. length bytes are copied into dst, starting at offset. This range's position is incremented by the number of bytes copied.
      Specified by:
      get in interface PositionedByteRange
      Parameters:
      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.
    • put

      public abstract PositionedByteRange put(byte val)
      Description copied from interface: PositionedByteRange
      Store val at the next position in this range.
      Specified by:
      put in interface PositionedByteRange
      Parameters:
      val - the new value.
      Returns:
      this.
    • put

      public abstract PositionedByteRange put(byte[] val)
      Description copied from interface: PositionedByteRange
      Store the content of val in this range, starting at the next position.
      Specified by:
      put in interface PositionedByteRange
      Parameters:
      val - the new value.
      Returns:
      this.
    • put

      public abstract PositionedByteRange put(byte[] val, int offset, int length)
      Description copied from interface: PositionedByteRange
      Store length bytes from val into this range. Bytes from val are copied starting at offset into the range, starting at the current position.
      Specified by:
      put in interface PositionedByteRange
      Parameters:
      val - the new value.
      offset - the offset in val from which to start copying.
      length - the number of bytes to copy from val.
      Returns:
      this.
    • putInt

      public abstract PositionedByteRange putInt(int index, int val)
      Description copied from interface: ByteRange
      Store the int value at index
      Specified by:
      putInt in interface ByteRange
      Specified by:
      putInt in interface PositionedByteRange
      Specified by:
      putInt in class AbstractByteRange
      Parameters:
      index - the index in the range where val is stored
      val - the value to store
      Returns:
      this
    • putLong

      public abstract PositionedByteRange putLong(int index, long val)
      Description copied from interface: ByteRange
      Store the long value at index
      Specified by:
      putLong in interface ByteRange
      Specified by:
      putLong in interface PositionedByteRange
      Specified by:
      putLong in class AbstractByteRange
      Parameters:
      index - the index in the range where val is stored
      val - the value to store
      Returns:
      this
    • putShort

      public abstract PositionedByteRange putShort(int index, short val)
      Description copied from interface: ByteRange
      Store the short value at index
      Specified by:
      putShort in interface ByteRange
      Specified by:
      putShort in interface PositionedByteRange
      Specified by:
      putShort in class AbstractByteRange
      Parameters:
      index - the index in the range where val is stored
      val - the value to store
      Returns:
      this
    • putInt

      public abstract PositionedByteRange putInt(int val)
      Description copied from interface: PositionedByteRange
      Store int val at the next position in this range.
      Specified by:
      putInt in interface PositionedByteRange
      Parameters:
      val - the new value.
      Returns:
      this.
    • putLong

      public abstract PositionedByteRange putLong(long val)
      Description copied from interface: PositionedByteRange
      Store long val at the next position in this range.
      Specified by:
      putLong in interface PositionedByteRange
      Parameters:
      val - the new value.
      Returns:
      this.
    • putShort

      public abstract PositionedByteRange putShort(short val)
      Description copied from interface: PositionedByteRange
      Store short val at the next position in this range.
      Specified by:
      putShort in interface PositionedByteRange
      Parameters:
      val - the new value.
      Returns:
      this.
    • putVLong

      public abstract int putVLong(int index, long val)
      Description copied from interface: ByteRange
      Store the long value at index as a VLong
      Specified by:
      putVLong in interface ByteRange
      Specified by:
      putVLong in class AbstractByteRange
      Parameters:
      index - the index in the range where val is stored
      val - the value to store
      Returns:
      number of bytes written
    • putVLong

      public abstract int putVLong(long val)
      Description copied from interface: PositionedByteRange
      Store the long val at the next position as a VLong
      Specified by:
      putVLong in interface PositionedByteRange
      Parameters:
      val - the value to store
      Returns:
      number of bytes written
    • get

      public PositionedByteRange 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
      Specified by:
      get in interface PositionedByteRange
      Overrides:
      get in class AbstractByteRange
      Parameters:
      index - zero-based index into this range.
      dst - the destination of the copy.
      Returns:
      this.
    • get

      public PositionedByteRange 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
      Specified by:
      get in interface PositionedByteRange
      Overrides:
      get in class AbstractByteRange
      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()
      Description copied from interface: PositionedByteRange
      Retrieve the next short value from this range.
      Specified by:
      getShort in interface PositionedByteRange
    • getInt

      public int getInt()
      Description copied from interface: PositionedByteRange
      Retrieve the next int value from this range.
      Specified by:
      getInt in interface PositionedByteRange
    • getLong

      public long getLong()
      Description copied from interface: PositionedByteRange
      Retrieve the next long value from this range.
      Specified by:
      getLong in interface PositionedByteRange
    • getVLong

      public long getVLong()
      Description copied from interface: PositionedByteRange
      Retrieve the next long value, which is stored as VLong, from this range
      Specified by:
      getVLong in interface PositionedByteRange
      Returns:
      the long value which is stored as VLong
    • put

      public abstract PositionedByteRange put(int index, byte val)
      Description copied from interface: ByteRange
      Store val at index.
      Specified by:
      put in interface ByteRange
      Specified by:
      put in interface PositionedByteRange
      Specified by:
      put in class AbstractByteRange
      Parameters:
      index - the index in the range where val is stored.
      val - the value to store.
      Returns:
      this.
    • put

      public abstract PositionedByteRange put(int index, byte[] val)
      Description copied from interface: ByteRange
      Store val at index.
      Specified by:
      put in interface ByteRange
      Specified by:
      put in interface PositionedByteRange
      Specified by:
      put in class AbstractByteRange
      Parameters:
      index - the index in the range where val is stored.
      val - the value to store.
      Returns:
      this.
    • put

      public abstract PositionedByteRange put(int index, byte[] val, int offset, int length)
      Description copied from interface: ByteRange
      Store length bytes from val into this range, starting at index. Bytes from val are copied starting at offset into the range.
      Specified by:
      put in interface ByteRange
      Specified by:
      put in interface PositionedByteRange
      Specified by:
      put in class AbstractByteRange
      Parameters:
      index - position in this range to start the copy.
      val - the value to store.
      offset - the offset in val from which to start copying.
      length - the number of bytes to copy from val.
      Returns:
      this.
    • deepCopy

      public abstract PositionedByteRange deepCopy()
      Description copied from interface: ByteRange
      Create a new ByteRange with new backing byte[] containing a copy of the content from this range's window.
      Specified by:
      deepCopy in interface ByteRange
      Specified by:
      deepCopy in interface PositionedByteRange
      Returns:
      Deep copy
    • shallowCopy

      public abstract PositionedByteRange shallowCopy()
      Description copied from interface: ByteRange
      Create a new ByteRange that points at this range's byte[]. Modifying the shallowCopy will modify the bytes in this range's array. Pass over the hash code if it is already cached.
      Specified by:
      shallowCopy in interface ByteRange
      Specified by:
      shallowCopy in interface PositionedByteRange
      Returns:
      new ByteRange object referencing this range's byte[].
    • shallowCopySubRange

      public abstract PositionedByteRange shallowCopySubRange(int innerOffset, int copyLength)
      Description copied from interface: ByteRange
      Create a new ByteRange that points at this range's byte[]. The new range can have different values for offset and length, but modifying the shallowCopy will modify the bytes in this range's array. Pass over the hash code if it is already cached.
      Specified by:
      shallowCopySubRange in interface ByteRange
      Specified by:
      shallowCopySubRange in interface PositionedByteRange
      Parameters:
      innerOffset - First byte of clone will be this.offset + copyOffset.
      copyLength - Number of bytes in the clone.
      Returns:
      new ByteRange object referencing this range's byte[].
    • setLimit

      public PositionedByteRange setLimit(int limit)
      Description copied from interface: PositionedByteRange
      Limits the byte range upto a specified value. Limit cannot be greater than capacity
      Specified by:
      setLimit in interface PositionedByteRange
      Returns:
      PositionedByteRange
    • getLimit

      public int getLimit()
      Description copied from interface: PositionedByteRange
      Return the current limit
      Specified by:
      getLimit in interface PositionedByteRange
      Returns:
      limit