SplitHistory implements Comparable<SplitHistory>, Serializable { public static SplitHistory parse(String history) { if (!history.matches(PATTERN)) { throw new SplitHistoryFormatException("History '" + history + "' doesn't match pattern '" + PATTERN + "'"); } String p = history.substring(1, history.length() - 1); String[] na = p.split(","); SplitHistory result = new SplitHistory(na.length + 2, false); for (int i = 0; i < na.length; i++) { SplitHistoryEntry n = SplitHistoryEntry.parse(na[i].trim()); if (i == 0) { validateRoot(n); } result.entries.add(n); } return result; } SplitHistory();  SplitHistory(int initialCapacity); private  SplitHistory(boolean addRoot); private  SplitHistory(int initialCapacity, boolean addRoot); int size(); List<SplitHistoryEntry> entries(); int[] indexPath(); String indexPathString(); SplitHistory[] split(int num); SplitHistory split(int index, boolean last); @Override int compareTo(SplitHistory history); boolean isPredecessor(SplitHistory history); boolean isSuccessor(SplitHistory history); boolean isFirstUpTo(int level); boolean isLastUpTo(int level); boolean isFirst(); boolean isLast(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static SplitHistory parse(String history); static final SplitHistory ROOT; }
@Test public void testParse() { assertEquals(history, SplitHistory.parse("[(0/1)]")); assertEquals(historySplit[0], SplitHistory.parse("[(0/1),(0/3)]")); assertEquals(historySplit[1], SplitHistory.parse("[(0/1),(1/3)]")); assertEquals(historySplit[2], SplitHistory.parse("[(0/1),(2/3)]")); }
@Test(expected = SplitHistoryFormatException.class) public void testParseFailFormatMissingBracket() { assertEquals(historySplit[2], SplitHistory.parse("[(0/1),(2/3)")); }
@Test(expected = IllegalArgumentException.class) public void testParseFailValueInvalidRoot() { assertEquals(historySplit[2], SplitHistory.parse("[(1/2),(2/3)]")); }
@Test(expected = SplitHistoryFormatException.class) public void testParseValueInvalidValues() { assertEquals(historySplit[2], SplitHistory.parse("[(0/1),(-1/3)]")); }
@Test(expected = IllegalArgumentException.class) public void testParseValueInvalidValues2() { assertEquals(historySplit[2], SplitHistory.parse("[(0/0)]")); }