StringView implements CharSequence { @Override public boolean equals(Object obj) { if (!(obj instanceof StringView)) { return false; } StringView other = (StringView) obj; int len = length(); if (len != other.length()) { return false; } String s1 = str; String s2 = other.str; int start1 = start; int start2 = other.start; while (start1 < end && start2 < other.end) { if (s1.charAt(start1) != s2.charAt(start2)) { return false; } start1++; start2++; } return true; } StringView(String data);  StringView(String str, int start, int end); String data(); int start(); int end(); char lastChar(); StringView subview(int start0, int end0); String repr(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); @Override int length(); @Override char charAt(int index); @Override CharSequence subSequence(int start, int end);  }
@SuppressWarnings("unlikely-arg-type") @Test public void testEquals() { String s1 = "..........abc.."; String s2 = "xyzabcxyz"; StringView v1 = new StringView(s1, 10, 13); StringView v2 = new StringView(s2, 3, 6); assertEquals(v1, v2); StringView v3 = new StringView(s1, 9, 12); assertNotEquals(v1, v3); assertFalse(v1.equals(null)); assertFalse(v1.equals("abc")); }