### Question:
CharSequences { public static int hashCode(CharSequence seq) { final int prime = 37; int result = 13; for (int i = 0, n = seq.length(); i < n; i += 1) { result = prime * result + seq.charAt(i); } return result; }  static int compare(CharSequence left, CharSequence right); static int hashCode(CharSequence seq);  }### Answer:
@Test public void testHashCode() { Utf8 first = new Utf8("abcd"); Utf8 second = new Utf8("abdd"); Assert.assertEquals("hashCode(Utf8) == hashCode(Utf8)", CharSequences.hashCode(first), CharSequences.hashCode(new Utf8(first))); Assert.assertEquals("hashCode(Utf8) == hashCode(String)", CharSequences.hashCode(first), CharSequences.hashCode(first.toString())); Assert.assertEquals("hashCode(String) == hashCode(String)", CharSequences.hashCode(first.toString()), CharSequences.hashCode(first.toString())); Assert.assertEquals("hashCode(Utf8) == hashCode(Utf8)", CharSequences.hashCode(second), CharSequences.hashCode(new Utf8(second))); Assert.assertEquals("hashCode(Utf8) == hashCode(String)", CharSequences.hashCode(second), CharSequences.hashCode(second.toString())); Assert.assertEquals("hashCode(String) == hashCode(String)", CharSequences.hashCode(second.toString()), CharSequences.hashCode(second.toString())); Assert.assertFalse("(a != b) => hashCode(a) != hashCode(b) (mostly)", CharSequences.hashCode(first) == CharSequences.hashCode(second)); }
@Test public void testCharSequenceSetEqualsAndHashCode() { List<String> stringColors = Lists.newArrayList( "orange", "green", "blue", "red", "purple", "red"); ImmutableCharSequenceSet strings = new ImmutableCharSequenceSet(stringColors); List<Utf8> utf8Colors = Lists.newArrayList( new Utf8("orange"), new Utf8("green"), new Utf8("blue"), new Utf8("red"), new Utf8("purple"), new Utf8("red")); ImmutableCharSequenceSet utf8s = new ImmutableCharSequenceSet(utf8Colors); Assert.assertEquals("Identical String and Utf8 sets should be equal", strings, utf8s); Assert.assertEquals("Sets equal => hash codes equal", strings.hashCode(), utf8s.hashCode()); }