|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hbase.util.ByteRange
public class ByteRange
Lightweight, reusable class for specifying ranges of byte[]'s. CompareTo and equals methods are lexicographic, which is native to HBase.
This class differs from ByteBuffer: On-heap bytes only Implements equals, hashCode, and compareTo so that it can be used in standard java Collections, similar to String. Does not maintain mark/position iterator state inside the class. Doing so leads to many bugs in complex applications. Allows the addition of simple core methods like this.copyTo(that, offset). Can be reused in tight loops like a major compaction which can save significant amounts of garbage. (Without reuse, we throw off garbage like this thing: http://www.youtube.com/watch?v=lkmBH-MjZF4 Mutable, and always evaluates equals, hashCode, and compareTo based on the current contents. Can contain convenience methods for comparing, printing, cloning, spawning new arrays, copying to other arrays, etc. Please place non-core methods intoByteRangeTool
.
We may consider converting this to an interface and creating separate implementations for a
single byte[], a paged byte[] (growable byte[][]), a ByteBuffer, etc
Constructor Summary | |
---|---|
ByteRange()
construct |
|
ByteRange(byte[] bytes)
|
|
ByteRange(byte[] bytes,
int offset,
int length)
|
Method Summary | |
---|---|
ByteRange |
clear()
write methods |
int |
compareTo(ByteRange other)
Bitwise comparison of each byte in the array. |
ByteRange |
deepCopy()
Create a new ByteRange with new backing byte[] and copy the state of this range into the new range. |
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)
standard methods |
byte |
get(int index)
|
byte[] |
getBytes()
|
int |
getLength()
|
int |
getOffset()
|
int |
hashCode()
|
boolean |
isEmpty()
|
static boolean |
isEmpty(ByteRange range)
static methods |
boolean |
notEmpty()
|
static boolean |
notEmpty(ByteRange range)
|
int |
numEqualPrefixBytes(ByteRange that,
int thatInnerOffset)
|
ByteRange |
set(byte[] bytes)
|
ByteRange |
set(byte[] bytes,
int offset,
int length)
|
void |
setLength(int length)
|
ByteRange |
shallowCopySubRange(int innerOffset,
int copyLength)
Create a new ByteRange that points at this range's byte[]. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ByteRange()
public ByteRange(byte[] bytes)
public ByteRange(byte[] bytes, int offset, int length)
Method Detail |
---|
public ByteRange clear()
public ByteRange set(byte[] bytes)
public ByteRange set(byte[] bytes, int offset, int length)
public void setLength(int length)
public byte get(int index)
index
- zero-based index
public byte[] deepCopyToNewArray()
public ByteRange deepCopy()
public void deepCopyTo(byte[] destination, int destinationOffset)
destination
- Copy to this arraydestinationOffset
- First index in the destination array.public void deepCopySubRangeTo(int innerOffset, int copyLength, byte[] destination, int destinationOffset)
innerOffset
- Start copying from this index in this source ByteRange. First byte copied is
bytes[offset + innerOffset]copyLength
- Copy this many bytesdestination
- Copy to this arraydestinationOffset
- First index in the destination array.public ByteRange shallowCopySubRange(int innerOffset, int copyLength)
innerOffset
- First byte of clone will be this.offset + copyOffset.copyLength
- Number of bytes in the clone.
public int numEqualPrefixBytes(ByteRange that, int thatInnerOffset)
public byte[] getBytes()
public int getOffset()
public int getLength()
public boolean isEmpty()
public boolean notEmpty()
public static boolean isEmpty(ByteRange range)
public static boolean notEmpty(ByteRange range)
public boolean equals(Object thatObject)
equals
in class Object
public int hashCode()
hashCode
in class Object
public int compareTo(ByteRange other)
compareTo
in interface Comparable<ByteRange>
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |