@Override public int hashCode() { int hash = 1; if (isBackedByArray()) { byte[] data = getBackingArray(); int end = offset() + length(); for (int i = offset(); i < end; i++) hash = (31 * hash) + data[i]; } else { for (int i = 0; i < length(); i++) hash = (31 * hash) + byteAt(i); } return hash; }
/** * Compares this byte sequence to another. * * @param obs byte sequence to compare * @return comparison result * @see #compareBytes(ByteSequence, ByteSequence) */ public int compareTo(ByteSequence obs) { if (isBackedByArray() && obs.isBackedByArray()) { return WritableComparator.compareBytes(getBackingArray(), offset(), length(), obs.getBackingArray(), obs.offset(), obs.length()); } return compareBytes(this, obs); }
public static ByteBuffer toByteBuffers(ByteSequence bs) { if (bs == null) return null; if (bs.isBackedByArray()) { return ByteBuffer.wrap(bs.getBackingArray(), bs.offset(), bs.length()); } else { // TODO create more efficient impl return ByteBuffer.wrap(bs.toArray()); } } }
/** * Compares the two given byte sequences, byte by byte, returning a negative, * zero, or positive result if the first sequence is less than, equal to, or * greater than the second. The comparison is performed starting with the * first byte of each sequence, and proceeds until a pair of bytes differs, * or one sequence runs out of byte (is shorter). A shorter sequence is * considered less than a longer one. * * @param bs1 first byte sequence to compare * @param bs2 second byte sequence to compare * @return comparison result */ public static int compareBytes(ByteSequence bs1, ByteSequence bs2) { int minLen = Math.min(bs1.length(), bs2.length()); for (int i = 0; i < minLen; i++) { int a = (bs1.byteAt(i) & 0xff); int b = (bs2.byteAt(i) & 0xff); if (a != b) { return a - b; } } return bs1.length() - bs2.length(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); String sep = ""; for (ByteSequence auth : auths) { sb.append(sep); sep = ","; sb.append(new String(auth.toArray(), Constants.UTF8)); } return sb.toString(); }
@Override public int hashCode() { int result = 0; for (ByteSequence b : auths) result += b.hashCode(); return result; }
public static ByteBuffer toByteBuffers(ByteSequence bs) { if (bs == null) return null; if (bs.isBackedByArray()) { return ByteBuffer.wrap(bs.getBackingArray(), bs.offset(), bs.length()); } else { // TODO create more efficient impl return ByteBuffer.wrap(bs.toArray()); } } }
/** * Compares the two given byte sequences, byte by byte, returning a negative, * zero, or positive result if the first sequence is less than, equal to, or * greater than the second. The comparison is performed starting with the * first byte of each sequence, and proceeds until a pair of bytes differs, * or one sequence runs out of byte (is shorter). A shorter sequence is * considered less than a longer one. * * @param bs1 first byte sequence to compare * @param bs2 second byte sequence to compare * @return comparison result */ public static int compareBytes(ByteSequence bs1, ByteSequence bs2) { int minLen = Math.min(bs1.length(), bs2.length()); for (int i = 0; i < minLen; i++) { int a = (bs1.byteAt(i) & 0xff); int b = (bs2.byteAt(i) & 0xff); if (a != b) { return a - b; } } return bs1.length() - bs2.length(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); String sep = ""; for (ByteSequence auth : auths) { sb.append(sep); sep = ","; sb.append(new String(auth.toArray(), Constants.UTF8)); } return sb.toString(); }
@Override public int hashCode() { int result = 0; for (ByteSequence b : auths) result += b.hashCode(); return result; }
/** * Compares this byte sequence to another. * * @param obs byte sequence to compare * @return comparison result * @see #compareBytes(ByteSequence, ByteSequence) */ public int compareTo(ByteSequence obs) { if (isBackedByArray() && obs.isBackedByArray()) { return WritableComparator.compareBytes(getBackingArray(), offset(), length(), obs.getBackingArray(), obs.offset(), obs.length()); } return compareBytes(this, obs); }
@Override public int hashCode() { int hash = 1; if (isBackedByArray()) { byte[] data = getBackingArray(); int end = offset() + length(); for (int i = offset(); i < end; i++) hash = (31 * hash) + data[i]; } else { for (int i = 0; i < length(); i++) hash = (31 * hash) + byteAt(i); } return hash; }