org.apache.hadoop.hbase.util
Class SimpleByteRange

java.lang.Object
  extended by org.apache.hadoop.hbase.util.SimpleByteRange
All Implemented Interfaces:
Comparable<ByteRange>, ByteRange
Direct Known Subclasses:
SimplePositionedByteRange

@InterfaceAudience.Public
@InterfaceStability.Evolving
public class SimpleByteRange
extends Object
implements ByteRange

A basic ByteRange implementation.


Field Summary
protected  byte[] bytes
          The array containing the bytes in this range.
protected  int length
          The number of bytes in the range.
protected  int offset
          The index of the first byte in this range.
 
Constructor Summary
SimpleByteRange()
          Create a new ByteRange lacking a backing array and with an undefined viewport.
SimpleByteRange(byte[] bytes)
          Create a new ByteRange over the provided bytes.
SimpleByteRange(byte[] bytes, int offset, int length)
          Create a new ByteRange over the provided bytes.
SimpleByteRange(int capacity)
          Create a new ByteRange over a new backing array of size capacity.
 
Method Summary
protected  void clearHashCache()
           
 int compareTo(ByteRange other)
          Bitwise comparison of each byte in the array.
 ByteRange deepCopy()
          Create a new ByteRange with new backing byte[] containing a copy of the content from this range's window.
 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[] deepCopyToNewArray()
          Instantiate a new byte[] with exact length, which is at least 24 bytes + length.
 boolean equals(Object thatObject)
           
 byte get(int index)
          Retrieve the byte at index.
 ByteRange get(int index, byte[] dst)
          Fill dst with bytes from the range, starting from index.
 ByteRange get(int index, byte[] dst, int offset, int length)
          Fill dst with bytes from the range, starting from index.
 byte[] getBytes()
          The underlying byte[].
 int getLength()
          The length of the range.
 int getOffset()
          The offset, the index into the underlying byte[] at which this range begins.
 int hashCode()
           
 boolean isEmpty()
           
static boolean isEmpty(ByteRange range)
           
 ByteRange put(int index, byte val)
          Store val at index.
 ByteRange put(int index, byte[] val)
          Store val at index.
 ByteRange put(int index, byte[] val, int offset, int length)
          Store length bytes from val into this range, starting at index.
 ByteRange set(byte[] bytes)
          Reuse this ByteRange over a new byte[].
 ByteRange set(byte[] bytes, int offset, int length)
          Reuse this ByteRange over a new byte[].
 ByteRange set(int capacity)
          Reuse this ByteRange over a new byte[].
 ByteRange setLength(int length)
          Update the length of this range.
 ByteRange setOffset(int offset)
          Update the beginning of this range.
 ByteRange shallowCopy()
          Create a new ByteRange that points at this range's byte[].
 ByteRange shallowCopySubRange(int innerOffset, int copyLength)
          Create a new ByteRange that points at this range's byte[].
 String toString()
           
 ByteRange unset()
          Nullifies this ByteRange.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

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

Constructor Detail

SimpleByteRange

public SimpleByteRange()
Create a new ByteRange lacking a backing array and with an undefined viewport.


SimpleByteRange

public SimpleByteRange(int capacity)
Create a new ByteRange over a new backing array of size capacity. The range's offset and length are 0 and capacity, respectively.

Parameters:
capacity - the size of the backing array.

SimpleByteRange

public SimpleByteRange(byte[] bytes)
Create a new ByteRange over the provided bytes.

Parameters:
bytes - The array to wrap.

SimpleByteRange

public SimpleByteRange(byte[] bytes,
                       int offset,
                       int length)
Create a new ByteRange over the provided bytes.

Parameters:
bytes - The array to wrap.
offset - The offset into bytes considered the beginning of this range.
length - The length of this range.
Method Detail

getBytes

public byte[] getBytes()
Description copied from interface: ByteRange
The underlying byte[].

Specified by:
getBytes in interface ByteRange

unset

public ByteRange 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
Returns:
this

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[].
Returns:
this

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.
Returns:
this

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:
ByteRange.getBytes()

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()
Specified by:
isEmpty in interface ByteRange
Returns:
true when this range is of zero length, false otherwise.

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.

put

public ByteRange put(int index,
                     byte val)
Description copied from interface: ByteRange
Store val at index.

Specified by:
put in interface ByteRange
Parameters:
index - the index in the range where val is stored.
val - the value to store.
Returns:
this.

put

public ByteRange put(int index,
                     byte[] val)
Description copied from interface: ByteRange
Store val at index.

Specified by:
put in interface ByteRange
Parameters:
index - the index in the range where val is stored.
val - the value to store.
Returns:
this.

put

public ByteRange 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
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.

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[].

deepCopy

public ByteRange 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
Returns:
Deep copy

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.

shallowCopy

public ByteRange 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
Returns:
new ByteRange object referencing this range's byte[].

shallowCopySubRange

public ByteRange 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
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[].

equals

public boolean equals(Object thatObject)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

clearHashCache

protected void clearHashCache()

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


Copyright © 2015 The Apache Software Foundation. All Rights Reserved.