@Override public int compareTo(ByteBuffer value, int offset, int length) { if (this.value.length <= length) { length = this.value.length; } return ByteBufferUtils.compareTo(this.value, 0, this.value.length, value, offset, length); }
@Override public int compareTo(ByteBuffer value, int offset, int length) { return ByteBufferUtils.compareTo(this.value, 0, this.value.length, value, offset, length); }
public static int compareTo(ByteBuffer buf1, int o1, int l1, byte[] buf2, int o2, int l2) { return compareTo(buf2, o2, l2, buf1, o1, l1)*-1; }
public static boolean equals(ByteBuffer buf1, int o1, int l1, byte[] buf2, int o2, int l2) { if ((l1 == 0) || (l2 == 0)) { // both 0 length, return true, or else false return l1 == l2; } // Since we're often comparing adjacent sorted data, // it's usual to have equal arrays except for the very last byte // so check that first if (toByte(buf1, o1 + l1 - 1) != buf2[o2 + l2 - 1]) return false; return compareTo(buf1, o1, l1, buf2, o2, l2) == 0; }
public static boolean equals(ByteBuffer buf1, int o1, int l1, ByteBuffer buf2, int o2, int l2) { if ((l1 == 0) || (l2 == 0)) { // both 0 length, return true, or else false return l1 == l2; } // Since we're often comparing adjacent sorted data, // it's usual to have equal arrays except for the very last byte // so check that first if (toByte(buf1, o1 + l1 - 1) != toByte(buf2, o2 + l2 - 1)) return false; return compareTo(buf1, o1, l1, buf2, o2, l2) == 0; }
private int compareRows(ByteBuffer row, Cell seekCell) { if (seekCell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.compareTo(row, row.position(), row.remaining(), ((ByteBufferExtendedCell) seekCell).getRowByteBuffer(), ((ByteBufferExtendedCell) seekCell).getRowPosition(), seekCell.getRowLength()); } else { return ByteBufferUtils.compareTo(row, row.position(), row.remaining(), seekCell.getRowArray(), seekCell.getRowOffset(), seekCell.getRowLength()); } }
private static int compareQualifierPart(Cell cell, int length, byte[] prefix) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.compareTo(((ByteBufferExtendedCell) cell).getQualifierByteBuffer(), ((ByteBufferExtendedCell) cell).getQualifierPosition(), length, prefix, 0, length); } return Bytes.compareTo(cell.getQualifierArray(), cell.getQualifierOffset(), length, prefix, 0, length); }
fillBB(bb2, (byte) 5); fillArray(b, (byte) 5); assertEquals(0, ByteBufferUtils.compareTo(bb1, 0, bb1.remaining(), bb2, 0, bb2.remaining())); assertTrue(ByteBufferUtils.compareTo(bb1, 0, bb1.remaining(), b, 0, b.length) > 0); bb2.put(134, (byte) 6); assertTrue(ByteBufferUtils.compareTo(bb1, 0, bb1.remaining(), bb2, 0, bb2.remaining()) < 0); bb2.put(6, (byte) 4); assertTrue(ByteBufferUtils.compareTo(bb1, 0, bb1.remaining(), bb2, 0, bb2.remaining()) > 0); byte[] b3 = new byte[135]; fillArray(b3, (byte)1); int result = ByteBufferUtils.compareTo(b3, 0, b3.length, bb3, 0, bb3.remaining()); assertTrue(result > 0); result = ByteBufferUtils.compareTo(bb3, 0, bb3.remaining(), b3, 0, b3.length); assertTrue(result < 0); bb4.put(i, b4[i - 10]); result = ByteBufferUtils.compareTo(b4, 0, b4.length, bb4, 10, b4.length); assertEquals(0, result);
public static boolean matchingValue(final Cell left, final byte[] buf) { if (left instanceof ByteBufferExtendedCell) { return ByteBufferUtils.compareTo(((ByteBufferExtendedCell) left).getValueByteBuffer(), ((ByteBufferExtendedCell) left).getValuePosition(), left.getValueLength(), buf, 0, buf.length) == 0; } return Bytes.equals(left.getValueArray(), left.getValueOffset(), left.getValueLength(), buf, 0, buf.length); }
static int compareRows(final Cell left, int leftRowLength, final Cell right, int rightRowLength) { // left and right can be exactly the same at the beginning of a row if (left == right) { return 0; } if (left instanceof ByteBufferExtendedCell && right instanceof ByteBufferExtendedCell) { return ByteBufferUtils.compareTo(((ByteBufferExtendedCell) left).getRowByteBuffer(), ((ByteBufferExtendedCell) left).getRowPosition(), leftRowLength, ((ByteBufferExtendedCell) right).getRowByteBuffer(), ((ByteBufferExtendedCell) right).getRowPosition(), rightRowLength); } if (left instanceof ByteBufferExtendedCell) { return ByteBufferUtils.compareTo(((ByteBufferExtendedCell) left).getRowByteBuffer(), ((ByteBufferExtendedCell) left).getRowPosition(), leftRowLength, right.getRowArray(), right.getRowOffset(), rightRowLength); } if (right instanceof ByteBufferExtendedCell) { // Notice how we flip the order of the compare here. We used to negate the return value but // see what FindBugs says // http://findbugs.sourceforge.net/bugDescriptions.html#RV_NEGATING_RESULT_OF_COMPARETO // It suggest flipping the order to get same effect and 'safer'. return ByteBufferUtils.compareTo(left.getRowArray(), left.getRowOffset(), leftRowLength, ((ByteBufferExtendedCell)right).getRowByteBuffer(), ((ByteBufferExtendedCell)right).getRowPosition(), rightRowLength); } return Bytes.compareTo(left.getRowArray(), left.getRowOffset(), left.getRowLength(), right.getRowArray(), right.getRowOffset(), right.getRowLength()); }
/** * Compares the cell's qualifier with the given byte[] * @param left the cell for which the qualifier has to be compared * @param right the byte[] having the qualifier * @param rOffset the offset of the qualifier * @param rLength the length of the qualifier * @return greater than 0 if left cell's qualifier is bigger than byte[], lesser than 0 if left * cell's qualifier is lesser than byte[] and 0 otherwise */ public final static int compareQualifiers(Cell left, byte[] right, int rOffset, int rLength) { if (left instanceof ByteBufferExtendedCell) { return ByteBufferUtils.compareTo(((ByteBufferExtendedCell) left).getQualifierByteBuffer(), ((ByteBufferExtendedCell) left).getQualifierPosition(), left.getQualifierLength(), right, rOffset, rLength); } return Bytes.compareTo(left.getQualifierArray(), left.getQualifierOffset(), left.getQualifierLength(), right, rOffset, rLength); }
/** * Compares the cell's family with the given byte[] * @param left the cell for which the family has to be compared * @param right the byte[] having the family * @param roffset the offset of the family * @param rlength the length of the family * @return greater than 0 if left cell's family is bigger than byte[], lesser than 0 if left * cell's family is lesser than byte[] and 0 otherwise */ public final static int compareFamilies(Cell left, byte[] right, int roffset, int rlength) { if (left instanceof ByteBufferExtendedCell) { return ByteBufferUtils.compareTo(((ByteBufferExtendedCell) left).getFamilyByteBuffer(), ((ByteBufferExtendedCell) left).getFamilyPosition(), left.getFamilyLength(), right, roffset, rlength); } return Bytes.compareTo(left.getFamilyArray(), left.getFamilyOffset(), left.getFamilyLength(), right, roffset, rlength); }
/** * Compares the row part of the cell with a simple plain byte[] like the * stopRow in Scan. This should be used with context where for hbase:meta * cells the {{@link #META_COMPARATOR} should be used * * @param left * the cell to be compared * @param right * the kv serialized byte[] to be compared with * @param roffset * the offset in the byte[] * @param rlength * the length in the byte[] * @return 0 if both cell and the byte[] are equal, 1 if the cell is bigger * than byte[], -1 otherwise */ @Override public int compareRows(Cell left, byte[] right, int roffset, int rlength) { if (left instanceof ByteBufferExtendedCell) { return ByteBufferUtils.compareTo(((ByteBufferExtendedCell) left).getRowByteBuffer(), ((ByteBufferExtendedCell) left).getRowPosition(), left.getRowLength(), right, roffset, rlength); } return Bytes.compareTo(left.getRowArray(), left.getRowOffset(), left.getRowLength(), right, roffset, rlength); }
@Override public int compareTo(ByteBuffer value, int offset, int length) { if (this.value.length <= length) { length = this.value.length; } return ByteBufferUtils.compareTo(this.value, 0, this.value.length, value, offset, length); }
@Override public int compareTo(ByteBuffer value, int offset, int length) { return ByteBufferUtils.compareTo(this.value, 0, this.value.length, value, offset, length); }
if (left instanceof ByteBufferExtendedCell && right instanceof ByteBufferExtendedCell) { return ByteBufferUtils .compareTo(((ByteBufferExtendedCell) left).getQualifierByteBuffer(), ((ByteBufferExtendedCell) left).getQualifierPosition(), left.getQualifierLength(), ((ByteBufferExtendedCell) right).getQualifierByteBuffer(), return ByteBufferUtils.compareTo(((ByteBufferExtendedCell) left).getQualifierByteBuffer(), ((ByteBufferExtendedCell) left).getQualifierPosition(), left.getQualifierLength(), right.getQualifierArray(), right.getQualifierOffset(), right.getQualifierLength()); return ByteBufferUtils.compareTo(left.getQualifierArray(), left.getQualifierOffset(), left.getQualifierLength(), ((ByteBufferExtendedCell)right).getQualifierByteBuffer(),
/** * Compare the families of left and right cell * @return 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise */ @Override public final int compareFamilies(Cell left, Cell right) { if (left instanceof ByteBufferExtendedCell && right instanceof ByteBufferExtendedCell) { return ByteBufferUtils.compareTo(((ByteBufferExtendedCell) left).getFamilyByteBuffer(), ((ByteBufferExtendedCell) left).getFamilyPosition(), left.getFamilyLength(), ((ByteBufferExtendedCell) right).getFamilyByteBuffer(), ((ByteBufferExtendedCell) right).getFamilyPosition(), right.getFamilyLength()); } if (left instanceof ByteBufferExtendedCell) { return ByteBufferUtils.compareTo(((ByteBufferExtendedCell) left).getFamilyByteBuffer(), ((ByteBufferExtendedCell) left).getFamilyPosition(), left.getFamilyLength(), right.getFamilyArray(), right.getFamilyOffset(), right.getFamilyLength()); } if (right instanceof ByteBufferExtendedCell) { // Notice how we flip the order of the compare here. We used to negate the return value but // see what FindBugs says // http://findbugs.sourceforge.net/bugDescriptions.html#RV_NEGATING_RESULT_OF_COMPARETO // It suggest flipping the order to get same effect and 'safer'. return ByteBufferUtils.compareTo( left.getFamilyArray(), left.getFamilyOffset(), left.getFamilyLength(), ((ByteBufferExtendedCell)right).getFamilyByteBuffer(), ((ByteBufferExtendedCell)right).getFamilyPosition(), right.getFamilyLength()); } return Bytes.compareTo(left.getFamilyArray(), left.getFamilyOffset(), left.getFamilyLength(), right.getFamilyArray(), right.getFamilyOffset(), right.getFamilyLength()); }
@Override public boolean filterRowKey(Cell firstRowCell) { if (firstRowCell == null || this.prefix == null) return true; if (filterAllRemaining()) return true; int length = firstRowCell.getRowLength(); if (length < prefix.length) return true; // if they are equal, return false => pass row // else return true, filter row // if we are passed the prefix, set flag int cmp; if (firstRowCell instanceof ByteBufferExtendedCell) { cmp = ByteBufferUtils.compareTo(((ByteBufferExtendedCell) firstRowCell).getRowByteBuffer(), ((ByteBufferExtendedCell) firstRowCell).getRowPosition(), this.prefix.length, this.prefix, 0, this.prefix.length); } else { cmp = Bytes.compareTo(firstRowCell.getRowArray(), firstRowCell.getRowOffset(), this.prefix.length, this.prefix, 0, this.prefix.length); } if ((!isReversed() && cmp > 0) || (isReversed() && cmp < 0)) { passedPrefix = true; } filterRow = (cmp != 0); return filterRow; }
int diff = ByteBufferUtils.compareTo(left.getRowByteBuffer(), left.getRowPosition(), leftRowLength, right.getRowByteBuffer(), right.getRowPosition(), rightRowLength); diff = ByteBufferUtils.compareTo(left.getFamilyByteBuffer(), leftFamilyPosition, leftFamilyLength, right.getFamilyByteBuffer(), rightFamilyPosition, rightFamilyLength); diff = ByteBufferUtils.compareTo(left.getQualifierByteBuffer(), left.getQualifierPosition(leftFamilyPosition, leftFamilyLength), leftQualifierLength, right.getQualifierByteBuffer(),
private static int compareQualifierPart(Cell cell, int length, byte[] prefix) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.compareTo(((ByteBufferExtendedCell) cell).getQualifierByteBuffer(), ((ByteBufferExtendedCell) cell).getQualifierPosition(), length, prefix, 0, length); } return Bytes.compareTo(cell.getQualifierArray(), cell.getQualifierOffset(), length, prefix, 0, length); }