@Test public void testGetSubString() { StringContainer a = new StringContainer(); try { a.getSubString(0); } catch (Exception e) { assertTrue(e instanceof IndexOutOfBoundsException); } a.addHead("a", "bbb", "cc"); assertEquals("a", a.getSubString(0)); assertEquals("cc", a.getSubString(-1)); assertEquals("bbb", a.getSubString(-2)); try { a.getSubString(4); } catch (Exception e) { assertTrue(e instanceof IndexOutOfBoundsException); } a.addTail("dd", "eeee"); assertEquals("a", a.getSubString(0)); assertEquals("cc", a.getSubString(-3)); assertEquals("dd", a.getSubString(3)); assertEquals("eeee", a.getSubString(-1)); try { a.getSubString(9); } catch (Exception e) { assertTrue(e instanceof IndexOutOfBoundsException); } }
public String getSubString(int index) { int realIndex = index >= 0 ? index : count + index; if (realIndex < 0 || realIndex >= count) { throw new IndexOutOfBoundsException( "Index: " + index + ", Real Index: " + realIndex + ", Size: " + count); } if (realIndex < reverseList.size()) { return reverseList.get(reverseList.size() - 1 - realIndex); } else { return sequenceList.get(realIndex - reverseList.size()); } }
StringContainer { public String getSubString(int index) { int realIndex = index >= 0 ? index : count + index; if (realIndex < 0 || realIndex >= count) { throw new IndexOutOfBoundsException( "Index: " + index + ", Real Index: " + realIndex + ", Size: " + count); } if (realIndex < reverseList.size()) { return reverseList.get(reverseList.size() - 1 - realIndex); } else { return sequenceList.get(realIndex - reverseList.size()); } } }
StringContainer { public String getSubString(int index) { int realIndex = index >= 0 ? index : count + index; if (realIndex < 0 || realIndex >= count) { throw new IndexOutOfBoundsException( "Index: " + index + ", Real Index: " + realIndex + ", Size: " + count); } if (realIndex < reverseList.size()) { return reverseList.get(reverseList.size() - 1 - realIndex); } else { return sequenceList.get(realIndex - reverseList.size()); } } StringContainer();  StringContainer(String joinSeparator);  StringContainer(String[] strings);  StringContainer(String[] strings, String joinSeparator); }
StringContainer { public String getSubString(int index) { int realIndex = index >= 0 ? index : count + index; if (realIndex < 0 || realIndex >= count) { throw new IndexOutOfBoundsException( "Index: " + index + ", Real Index: " + realIndex + ", Size: " + count); } if (realIndex < reverseList.size()) { return reverseList.get(reverseList.size() - 1 - realIndex); } else { return sequenceList.get(realIndex - reverseList.size()); } } StringContainer();  StringContainer(String joinSeparator);  StringContainer(String[] strings);  StringContainer(String[] strings, String joinSeparator); int size(); int length(); ArrayList<String> getSequenceList(); ArrayList<String> getReverseList(); StringContainer addTail(Object... objs); StringContainer addTail(String... strings); StringContainer addTail(StringContainer myContainer); StringContainer addHead(String... strings); StringContainer addHead(StringContainer myContainer); @Override String toString(); String join(String separator); String getSubString(int index); StringContainer getSubStringContainer(int start, int end); @Override int hashCode(); @Override boolean equals(Object sc); boolean equals(StringContainer sc); @Override StringContainer clone(); }
StringContainer { public String getSubString(int index) { int realIndex = index >= 0 ? index : count + index; if (realIndex < 0 || realIndex >= count) { throw new IndexOutOfBoundsException( "Index: " + index + ", Real Index: " + realIndex + ", Size: " + count); } if (realIndex < reverseList.size()) { return reverseList.get(reverseList.size() - 1 - realIndex); } else { return sequenceList.get(realIndex - reverseList.size()); } } StringContainer();  StringContainer(String joinSeparator);  StringContainer(String[] strings);  StringContainer(String[] strings, String joinSeparator); int size(); int length(); ArrayList<String> getSequenceList(); ArrayList<String> getReverseList(); StringContainer addTail(Object... objs); StringContainer addTail(String... strings); StringContainer addTail(StringContainer myContainer); StringContainer addHead(String... strings); StringContainer addHead(StringContainer myContainer); @Override String toString(); String join(String separator); String getSubString(int index); StringContainer getSubStringContainer(int start, int end); @Override int hashCode(); @Override boolean equals(Object sc); boolean equals(StringContainer sc); @Override StringContainer clone();  }