public void testLexicographicalComparator() { List<byte[]> ordered = Arrays.asList( new byte[] {}, new byte[] {LEAST}, new byte[] {LEAST, LEAST}, new byte[] {LEAST, (byte) 1}, new byte[] {(byte) 1}, new byte[] {(byte) 1, LEAST}, new byte[] {GREATEST, GREATEST - (byte) 1}, new byte[] {GREATEST, GREATEST}, new byte[] {GREATEST, GREATEST, GREATEST}); Comparator<byte[]> comparator = SignedBytes.lexicographicalComparator(); Helpers.testComparator(comparator, ordered); }
@GwtIncompatible // SerializableTester public void testLexicographicalComparatorSerializable() { Comparator<byte[]> comparator = SignedBytes.lexicographicalComparator(); assertSame(comparator, SerializableTester.reserialize(comparator)); }
@Override public int compare(INode left, INode right) { if (left == null) { return right == null ? 0 : -1; } else { if (right == null) { return 1; } else { int cmp = compare(left.getParent(), right.getParent()); return cmp == 0 ? SignedBytes.lexicographicalComparator().compare( left.getLocalNameBytes(), right.getLocalNameBytes()) : cmp; } } } };
/** Compare two byte arrays by lexicographical order. */ public static int compareBytes(byte[] left, byte[] right) { if (left == null) { left = EMPTY_BYTES; } if (right == null) { right = EMPTY_BYTES; } return SignedBytes.lexicographicalComparator().compare(left, right); }
/** Compare two byte arrays by lexicographical order. */ public static int compareBytes(byte[] left, byte[] right) { if (left == null) { left = EMPTY_BYTES; } if (right == null) { right = EMPTY_BYTES; } return SignedBytes.lexicographicalComparator().compare(left, right); }
@Override public int compare(DiffReportListingEntry left, DiffReportListingEntry right) { final Comparator<byte[]> cmp = SignedBytes.lexicographicalComparator(); //source path can never be null final byte[][] l = left.getSourcePath(); final byte[][] r = right.getSourcePath(); if (l.length == 1 && l[0] == null) { return -1; } else if (r.length == 1 && r[0] == null) { return 1; } else { for (int i = 0; i < l.length && i < r.length; i++) { final int diff = cmp.compare(l[i], r[i]); if (diff != 0) { return diff; } } return l.length == r.length ? 0 : l.length > r.length ? 1 : -1; } } };
public void testLexicographicalComparator() { List<byte[]> ordered = Arrays.asList( new byte[] {}, new byte[] {LEAST}, new byte[] {LEAST, LEAST}, new byte[] {LEAST, (byte) 1}, new byte[] {(byte) 1}, new byte[] {(byte) 1, LEAST}, new byte[] {GREATEST, GREATEST - (byte) 1}, new byte[] {GREATEST, GREATEST}, new byte[] {GREATEST, GREATEST, GREATEST}); Comparator<byte[]> comparator = SignedBytes.lexicographicalComparator(); Helpers.testComparator(comparator, ordered); }
@Override public int compare(INode left, INode right) { if (left == null) { return right == null ? 0 : -1; } else { if (right == null) { return 1; } else { int cmp = compare(left.getParent(), right.getParent()); return cmp == 0 ? SignedBytes.lexicographicalComparator().compare( left.getLocalNameBytes(), right.getLocalNameBytes()) : cmp; } } } };
@GwtIncompatible // SerializableTester public void testLexicographicalComparatorSerializable() { Comparator<byte[]> comparator = SignedBytes.lexicographicalComparator(); assertSame(comparator, SerializableTester.reserialize(comparator)); }