StringView implements CharSequence { public String repr() { if (repr == null) { repr = str.substring(this.start, this.end); } return repr; } 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);  }
@Test public void testRepr() { String s1 = "foobar"; StringView view = new StringView(s1); assertEquals(view.repr(), s1); String s2 = "..........abc.."; StringView v1 = new StringView(s2, 10, 13); assertEquals(v1.start(), 10); assertEquals(v1.end(), 13); assertEquals(v1.length(), 3); StringView v2 = new StringView("abcdefghij"); StringView v3 = v2.subview(1, 5); assertEquals(v3.start(), 1); assertEquals(v3.end(), 5); assertEquals(v3.repr(), "bcde"); StringView v4 = v3.subview(1, 2); assertEquals(v4.start(), 2); assertEquals(v4.end(), 3); assertEquals(v4.repr(), "c"); assertEquals(v4.repr(), "c"); assertEquals(v4.repr(), "c"); }