@Test public void testCompareBytes() { ByteSequence a = new ArrayByteSequence("a"); ByteSequence b = new ArrayByteSequence("b"); ByteSequence abc = new ArrayByteSequence("abc"); assertLessThan(a, b); assertLessThan(a, abc); assertLessThan(abc, b); }
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(); }
ByteSequence implements Comparable<ByteSequence> { 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(); } }
ByteSequence implements Comparable<ByteSequence> { 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(); }  }
ByteSequence implements Comparable<ByteSequence> { 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(); }  abstract byte byteAt(int i); abstract int length(); abstract ByteSequence subSequence(int start, int end); abstract byte[] toArray(); abstract boolean isBackedByArray(); abstract byte[] getBackingArray(); abstract int offset(); static int compareBytes(ByteSequence bs1, ByteSequence bs2); @Override int compareTo(ByteSequence obs); @Override boolean equals(Object o); @Override int hashCode(); }
ByteSequence implements Comparable<ByteSequence> { 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(); }  abstract byte byteAt(int i); abstract int length(); abstract ByteSequence subSequence(int start, int end); abstract byte[] toArray(); abstract boolean isBackedByArray(); abstract byte[] getBackingArray(); abstract int offset(); static int compareBytes(ByteSequence bs1, ByteSequence bs2); @Override int compareTo(ByteSequence obs); @Override boolean equals(Object o); @Override int hashCode();  }