@Test public void testCompareEqualLength() { Utf8 first = new Utf8("abcd"); Utf8 second = new Utf8("abdd"); int cmp = first.compareTo(first); Assert.assertEquals("Utf8 and String compareTo should agree", cmp, first.toString().compareTo(first.toString())); Assert.assertEquals("compare(Utf8,Utf8)", cmp, CharSequences.compare(first, first)); Assert.assertEquals("compare(Utf8,Utf8)", cmp, CharSequences.compare(first, new Utf8(first))); Assert.assertEquals("compare(String,Utf8)", cmp, CharSequences.compare(first.toString(), first)); Assert.assertEquals("compare(Utf8,String)", cmp, CharSequences.compare(first, first.toString())); Assert.assertEquals("compare(String,String)", cmp, CharSequences.compare(first.toString(), first.toString())); cmp = first.compareTo(second); Assert.assertEquals("Utf8 and String compareTo should agree", cmp, first.toString().compareTo(second.toString())); Assert.assertEquals("compare(Utf8,Utf8)", cmp, CharSequences.compare(first, second)); Assert.assertEquals("compare(String,Utf8)", cmp, CharSequences.compare(first.toString(), second)); Assert.assertEquals("compare(Utf8,String)", cmp, CharSequences.compare(first, second.toString())); Assert.assertEquals("compare(String,String)", cmp, CharSequences.compare(first.toString(), second.toString())); cmp = second.compareTo(first); Assert.assertEquals("Utf8 and String compareTo should agree", cmp, second.toString().compareTo(first.toString())); Assert.assertEquals("compare(Utf8,Utf8)", cmp, CharSequences.compare(second, first)); Assert.assertEquals("compare(String,Utf8)", cmp, CharSequences.compare(second.toString(), first)); Assert.assertEquals("compare(Utf8,String)", cmp, CharSequences.compare(second, first.toString())); Assert.assertEquals("compare(String,String)", cmp, CharSequences.compare(second.toString(), first.toString())); }
public static int compare(CharSequence left, CharSequence right) { if (left == right) { return 0; } int minLength = Math.min(left.length(), right.length()); for (int i = 0; i < minLength; i += 1) { int cmp = (left.charAt(i) - right.charAt(i)); if (cmp != 0) { return cmp; } } return (left.length() - right.length()); }
CharSequences { public static int compare(CharSequence left, CharSequence right) { if (left == right) { return 0; } int minLength = Math.min(left.length(), right.length()); for (int i = 0; i < minLength; i += 1) { int cmp = (left.charAt(i) - right.charAt(i)); if (cmp != 0) { return cmp; } } return (left.length() - right.length()); } }
CharSequences { public static int compare(CharSequence left, CharSequence right) { if (left == right) { return 0; } int minLength = Math.min(left.length(), right.length()); for (int i = 0; i < minLength; i += 1) { int cmp = (left.charAt(i) - right.charAt(i)); if (cmp != 0) { return cmp; } } return (left.length() - right.length()); }  }
CharSequences { public static int compare(CharSequence left, CharSequence right) { if (left == right) { return 0; } int minLength = Math.min(left.length(), right.length()); for (int i = 0; i < minLength; i += 1) { int cmp = (left.charAt(i) - right.charAt(i)); if (cmp != 0) { return cmp; } } return (left.length() - right.length()); }  static int compare(CharSequence left, CharSequence right); static int hashCode(CharSequence seq); }
CharSequences { public static int compare(CharSequence left, CharSequence right) { if (left == right) { return 0; } int minLength = Math.min(left.length(), right.length()); for (int i = 0; i < minLength; i += 1) { int cmp = (left.charAt(i) - right.charAt(i)); if (cmp != 0) { return cmp; } } return (left.length() - right.length()); }  static int compare(CharSequence left, CharSequence right); static int hashCode(CharSequence seq);  }