Bytes { public static int compare(byte[] x1, byte[] x2) { int n = Math.min(x1.length, x2.length) ; for ( int i = 0 ; i < n ; i++ ) { byte b1 = x1[i] ; byte b2 = x2[i] ; if ( b1 == b2 ) continue ; return (b1&0xFF) - (b2&0xFF) ; } return x1.length - x2.length ; } private  Bytes(); static int compare(byte[] x1, byte[] x2); static int compareByte(byte b1, byte b2); static byte[] copyOf(byte[] bytes); static byte[] copyOf(byte[] bytes, int start); static byte[] copyOf(byte[] bytes, int start, int length); static byte[] intToBytes(int v); static byte[] longToBytes(long v); static final int getInt(byte[]b); static final int getInt(byte[]b, int idx); static final long getLong(byte[]b); static final long getLong(byte[]b, int idx); static final void setInt(int value, byte[]b); static final void setInt(int x, byte[]b, int idx); static final void setLong(long value, byte[]b); static final void setLong(long value, byte[] b, int idx); static byte[] packInt(int val); static byte[] packLong(long val); static byte[] string2bytes(String x); static String bytes2string(byte[] x); static int toByteBuffer(CharSequence s, ByteBuffer bb); static int toByteBuffer(CharSequence s, ByteBuffer bb, CharsetEncoder enc); static String fromByteBuffer(ByteBuffer bb); static String fromByteBuffer(ByteBuffer bb, CharsetDecoder dec); static String asHex(byte[] bytes); static String asHexUC(byte[] bytes); static String asHexLC(byte[] bytes); static String asHex(byte[] bytes, int start, int finish, char[] hexDigits); static String asHex(byte b); static String asHexUC(byte b); static String asHexLC(byte b); static int hexCharToInt(char c); final static byte[] hexDigitsUC; final static byte[] hexDigitsLC; }
@Test public void compare1() { compare(0, new byte[]{}, new byte[]{}); }
@Test public void compare2() { compare(+1, new byte[]{1}, new byte[]{}); }
@Test public void compare3() { compare(-1, new byte[]{1}, new byte[]{1,2}); }
@Test public void compare4() { compare(+1, new byte[]{1,3}, new byte[]{1,2}); }
@Test public void compare5() { compare(+1, new byte[]{1,3}, new byte[]{1,2,3}); }
@Test public void compare6() { compare(-1, new byte[]{1,2}, new byte[]{1,2,3}); }