private Behavior mergePaths(LinkedList<Behavior> list1, LinkedList<Behavior> list2, LinkedList<Behavior> lcs) { Behavior start = null; Behavior last = null; Behavior line1Start = null; Behavior line2Start = null; Behavior holdLast; Behavior holdCurrent; LinkedList<Behavior>.Enumerator enumerator1 = list1.GetEnumerator(); LinkedList<Behavior>.Enumerator enumerator2 = list2.GetEnumerator(); for (LinkedList<Behavior>.Enumerator lcsEnumerator = lcs.GetEnumerator(); lcsEnumerator.MoveNext(); ) { line1Start = null; line2Start = null; holdLast = null; while (enumerator1.MoveNext() && enumerator1.Current.compareTo(lcsEnumerator.Current) != 0) { holdCurrent = enumerator1.Current.makeCopy(); if (line1Start == null) { line1Start = holdCurrent; } else { holdLast.setNext(holdCurrent); } holdLast = holdCurrent; } if (line1Start != null) { holdLast.setNext(lcsEnumerator.Current); } holdLast = null; while (enumerator2.MoveNext() && enumerator2.Current.compareTo(lcsEnumerator.Current) != 0) { holdCurrent = enumerator2.Current.makeCopy(); if (line2Start == null) { line2Start = holdCurrent; } else { holdLast.setNext(holdCurrent); } holdLast = holdCurrent; } if (line2Start != null) { holdLast.setNext(lcsEnumerator.Current); } if (line1Start == null && line2Start == null) { holdCurrent = lcsEnumerator.Current; } else { holdCurrent = new ComboBehavior(); holdCurrent.setNext(line1Start == null ? lcsEnumerator.Current : line1Start); holdCurrent.setNext(line2Start == null ? lcsEnumerator.Current : line2Start); } if (start == null) { start = holdCurrent; } else { last.setNext(holdCurrent); } last = lcsEnumerator.Current; } return start; }
private void foldIn(LinkedList<Behavior> llb, LinkedList<Behavior> lcs) { bool go; bool start = true; bool pause = false; Behavior holdCurrent; Behavior holdLast; Behavior node = startPoint; Behavior lineStart; LinkedList<Behavior>.Enumerator e = llb.GetEnumerator(); for (LinkedList<Behavior>.Enumerator lcsEnumerator = lcs.GetEnumerator(); pause || lcsEnumerator.MoveNext(); ) { if (!start) { node = lcsEnumerator.Current; } lineStart = null; holdLast = null; go = e.MoveNext(); while (go && e.Current.compareTo(lcsEnumerator.Current) != 0) { holdCurrent = e.Current.makeCopy(); if (lineStart == null) { lineStart = holdCurrent; } else { holdLast.setNext(holdCurrent); } holdLast = holdCurrent; go = e.MoveNext(); } if (lineStart != null && go) { holdLast.setNext(node); } if (node is ComboBehavior) { bool moveOn = false; foreach (Behavior b in ((ComboBehavior)node).getAllBranches()) { if (b.compareTo(lcsEnumerator.Current) == 0 && lineStart == null) { moveOn = true; break; } } if (!moveOn) { node.setNext(lineStart == null ? lcsEnumerator.Current : lineStart); } } // Make a combo behavior if this isn't just the same LCS node. else if (!(lineStart == null && node.compareTo(lcsEnumerator.Current) == 0)) { ComboBehavior cb = new ComboBehavior(); cb.setNext(node); cb.setNext(lcsEnumerator.Current); startPoint = cb; } else { lineStart = lcsEnumerator.Current; pause = start; } start = false; } }