SplitHistory implements Comparable<SplitHistory>, Serializable { public boolean isPredecessor(SplitHistory history) { int ts = size(); int ps = history.size(); int last = -1; SplitHistoryEntry tn = null; SplitHistoryEntry pn = null; for (int i = 0; i < Math.min(ts, ps); i++) { last = i; tn = entries.get(i); pn = history.entries.get(i); if (tn.getIndex() != pn.getIndex()) { break; } } if (!tn.isPredecessor(pn)) { return false; } if (!isLastUpTo(last)) { return false; } if (!history.isFirstUpTo(last)) { return false; } return true; } 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 testIsPredecessor() { String id = "[(0/1),(0/2),(0/4),(0/2)]"; assertFalse(SplitHistory.parse(id) .isPredecessor(SplitHistory.parse(id))); assertFalse(SplitHistory.parse(id).isSuccessor(SplitHistory.parse(id))); id = "[(0/1),(1/2),(0/1234)]"; assertFalse(SplitHistory.parse(id) .isPredecessor(SplitHistory.parse(id))); assertFalse(SplitHistory.parse(id).isSuccessor(SplitHistory.parse(id))); String p1 = "[(0/1),(0/2),(1/3)]"; String p2 = "[(0/1),(0/2),(2/3)]"; assertTrue(SplitHistory.parse(p1).isPredecessor(SplitHistory.parse(p2))); assertFalse(SplitHistory.parse(p2) .isPredecessor(SplitHistory.parse(p1))); p1 = "[(0/1),(0/2),(2/3)]"; p2 = "[(0/1),(1/2),(0/2),(0/4)]"; assertTrue(SplitHistory.parse(p1).isPredecessor(SplitHistory.parse(p2))); assertFalse(SplitHistory.parse(p2) .isPredecessor(SplitHistory.parse(p1))); p1 = "[(0/1),(1/2),(0/2),(2/4)]"; p2 = "[(0/1),(1/2),(0/2),(3/4),(0/3)]"; assertTrue(SplitHistory.parse(p1).isPredecessor(SplitHistory.parse(p2))); assertFalse(SplitHistory.parse(p2) .isPredecessor(SplitHistory.parse(p1))); p1 = "[(0/1),(1/2),(0/2),(2/4)]"; p2 = "[(0/1),(1/2),(0/2),(1/4),(0/3)]"; assertFalse(SplitHistory.parse(p1) .isPredecessor(SplitHistory.parse(p2))); assertFalse(SplitHistory.parse(p2) .isPredecessor(SplitHistory.parse(p1))); p1 = "[(0/1),(1/2),(0/2),(2/4)]"; p2 = "[(0/1),(1/2),(1/2),(0/4),(0/3)]"; assertFalse(SplitHistory.parse(p1) .isPredecessor(SplitHistory.parse(p2))); assertFalse(SplitHistory.parse(p2) .isPredecessor(SplitHistory.parse(p1))); p1 = "[(0/1),(1/2),(0/2),(3/4),(2/3)]"; p2 = "[(0/1),(1/2),(1/2)]"; assertTrue(SplitHistory.parse(p1).isPredecessor(SplitHistory.parse(p2))); assertFalse(SplitHistory.parse(p2) .isPredecessor(SplitHistory.parse(p1))); p1 = "[(0/1)]"; p2 = "[(0/1)]"; assertFalse(SplitHistory.parse(p1) .isPredecessor(SplitHistory.parse(p2))); assertFalse(SplitHistory.parse(p2) .isPredecessor(SplitHistory.parse(p1))); p1 = "[(0/1),(0/2)]"; p2 = "[(0/1),(0/2)]"; assertFalse(SplitHistory.parse(p1) .isPredecessor(SplitHistory.parse(p2))); assertFalse(SplitHistory.parse(p2) .isPredecessor(SplitHistory.parse(p1))); p1 = "[(0/1),(0/2)]"; p2 = "[(0/1),(0/2),(0/2)]"; assertFalse(SplitHistory.parse(p1) .isPredecessor(SplitHistory.parse(p2))); assertFalse(SplitHistory.parse(p2) .isPredecessor(SplitHistory.parse(p1))); }