/** * Tests whether two byte arrays have the same contents. * @param a First non-{@code null} byte array to compare. * @param b Second non-{@code null} byte array to compare. * @return {@code true} if the two arrays are identical, * {@code false} otherwise. */ public static boolean equals(final byte[] a, final byte[] b) { return memcmp(a, b) == 0; }
private static boolean byteArrayEquals(byte[][] self, byte[][] other) { if (self.length != other.length) { return false; } for (int i = 0; i < self.length; i++) { if (Bytes.memcmp(self[i], other[i]) != 0) { return false; } } return true; }
/** * De-duplicates two byte arrays. * <p> * If two byte arrays have the same contents but are different, this * function helps to re-use the old one and discard the new copy. * @param old The existing byte array. * @param neww The new byte array we're trying to de-duplicate. * @return {@code old} if {@code neww} is a different array with the same * contents, otherwise {@code neww}. */ public static byte[] deDup(final byte[] old, final byte[] neww) { return memcmp(old, neww) == 0 ? old : neww; }
@Override public int compareTo(final RegionInfo other) { return Bytes.memcmp(region_name, other.region_name); }
@Override public int compare(final byte[] a, final byte[] b) { return memcmp(a, b); }
public int compareTo(final Cell other) { return Bytes.memcmp(qualifier, other.qualifier); }
/** * {@code memcmp(3)} in Java for possibly {@code null} arrays, hooray. * @param a First possibly {@code null} byte array to compare. * @param b Second possibly {@code null} byte array to compare. * @return 0 if the two arrays are identical (or both are {@code null}), * otherwise the difference between the first two different bytes (treated * as unsigned), otherwise the different between their lengths (a {@code * null} byte array is considered shorter than an empty byte array). */ public static int memcmpMaybeNull(final byte[] a, final byte[] b) { if (a == null) { if (b == null) { return 0; } return -1; } else if (b == null) { return 1; } return memcmp(a, b); }
@Override public int compareTo(final KeyValue other) { int d; if ((d = Bytes.memcmp(key, other.key)) != 0) { return d; } else if ((d = Bytes.memcmp(family, other.family)) != 0) { return d; } else if ((d = Bytes.memcmp(qualifier, other.qualifier)) != 0) { return d; //} else if ((d = Bytes.memcmp(value, other.value)) != 0) { // return d; } else if ((d = Long.signum(timestamp - other.timestamp)) != 0) { return d; } else { // d = type - other.type; d = Bytes.memcmp(value, other.value); } return d; }
/** * Helper comparison function to compare tag name IDs. * * @param name_width Number of bytes used by a tag name ID. * @param tag A tag (array containing a tag name ID and a tag value ID). * @param group_by A tag name ID. * @return {@code true} number if {@code tag} should be used next (because * it contains a smaller ID), {@code false} otherwise. */ private boolean isTagNext(final short name_width, final byte[] tag, final byte[] group_by) { if (tag == null) { return false; } else if (group_by == null) { return true; } final int cmp = Bytes.memcmp(tag, group_by, 0, name_width); if (cmp == 0) { throw new AssertionError("invariant violation: tag ID " + Arrays.toString(group_by) + " is both in 'tags' and" + " 'group_bys' in " + this); } return cmp < 0; }
@Override /** * Compares two RPCs. */ public int compare(final BatchableRpc a, final BatchableRpc b) { int d; if ((d = Bytes.memcmp(a.getRegion().name(), b.getRegion().name())) != 0) { return d; } else if ((d = a.code() - b.code()) != 0) { // Sort by code before key. // Note that DeleteRequest.code() < PutRequest.code() and this matters // as the RegionServer processes deletes before puts, and we want to // send RPCs in the same order as they will be processed. return d; } else if ((d = Bytes.memcmp(a.key, b.key)) != 0) { return d; } return Bytes.memcmp(a.family(), b.family()); }
@Override /** * Compares two RPCs. */ public int compare(final ActionEntry a, final ActionEntry b) { return Bytes.memcmp(a.rpc.getRegion().name(), b.rpc.getRegion().name()); } }
for (final ArrayList<KeyValue> row : rows) { final byte[] key = row.get(0).key(); if (Bytes.memcmp(metric, key, 0, metric_width) != 0) { throw new IllegalDataException("HBase returned a row that doesn't match" + " our scanner (" + scanner + ")! " + row + " does not start"
&& Bytes.memcmp(key, stop_key) >= 0) {