Calc { public final static int compareUAsPrefix(byte[] v1, byte[] v2) { if(comparsionOfNull(v1, v2) != Integer.MAX_VALUE) return comparsionOfNull(v1, v2); int len1 = v1.length; int len2 = v2.length; int len = Math.min(len1, len2); int pos = -1; while (++pos < len) { int b1 = v1[pos] & 0xFF; int b2 = v2[pos] & 0xFF; if (b1 != b2) { return b1 - b2; } } return (len1 <= len2) ? 0 : 1; }  static byte[] fromBigDecimal(BigDecimal i); static BigDecimal toBigDecimal(byte[] b); static BigDecimal toBigDecimal(byte[] b, int off, int len); static BigInteger toBigInteger(byte[] b); static BigInteger toBigInteger(byte[] b, int off, int len); static byte[] fromBigInteger(BigInteger i); static void fromBigInteger(BigInteger i, byte[] b, int off); static String toString(byte[] s); static String toString(byte[] s, int off, int len); static byte[] fromString(String s); static void fromString(String s, byte[] b, int off); static int toUIntVar(byte[] b); static int toInt(byte[] b, int off, int len); static byte[] fromUIntVar(int i); static int toInt(byte[] b); static int toInt(byte[] b, int off); static byte[] fromInt(int i); static void fromInt(int i, byte[] b, int off); static long toLong(byte[] b); static long toLong(byte[] b, int off); static byte[] fromLong(long i); static void fromLong(long i, byte[] b, int off); static double toDouble(byte[] b); static double toDouble(byte[] b, int off); static byte[] fromDouble(double i); static void fromDouble(double i, byte[] b, int off); static float toFloat(byte[] b); static float toFloat(byte[] b, int off); static byte[] fromFloat(float i); static void fromDouble(float i, byte[] b, int off); static int compare(byte[] v1, byte[] v2); static int compare(byte[] v1, int off1, int len1, byte[] v2, int off2, int len2); final static int compareAsPrefix(byte[] v1, byte[] v2); static int compareU(byte[] v1, byte[] v2); static int compareU(byte[] v1, int off1, int len1, byte[] v2, int off2, int len2); final static int compareUAsPrefix(byte[] v1, byte[] v2); static int compareUIntVar(byte[] v1, byte[] v2); static int compareInt(byte[] v1, byte[] v2); static int compareInt(byte[] v1, int off1, byte[] v2, int off2); static int compareLong(byte[] v1, byte[] v2); static int compareLong(byte[] v1, int off1, byte[] v2, int off2); static int compareDouble(byte[] v1, byte[] v2); static int compareFloat(byte[] v1, byte[] v2); static int compareBigInteger(byte[] v1, byte[] v2); static int compareBigDecimal(byte[] v1, byte[] v2);  }
@Test public void compareUAsPrefix(){ byte[] value1 = new byte[]{2, 2, 2,2}; assertEquals("Null, which should be maximum value, is smaller that non null.", -1, Calc.compareUAsPrefix(value1, null)); assertEquals("Null, which should be maximum value, is smaller that non null.", 1, Calc.compareUAsPrefix(null, value1)); assertEquals("Both are the largest possible value and thus equal.", 0, Calc.compareUAsPrefix(null, null)); byte[] value2 = new byte[]{1, 1, 1, 1}; assertEquals("Comparison where the first value is larger than the second gave error.", 1, Calc.compareUAsPrefix(value1, value2)); byte[] value3 = new byte[]{2, 2, 2, 2, 2}; assertEquals("Comparison where one is longer than the other gave the incorrect result", 1, Calc.compareUAsPrefix(value3, value1)); }