Source:
<code>public T toRoot() { if (breadcrumbs.size() == 0 && modificationType != ModificationType.DELETE) { return this.curNode; } if (breadcrumbs.size() == 0 && modificationType == ModificationType.DELETE) { return null; } T curNode = this.curNode; Breadcrumb<T> firstBreadcrumb = breadcrumbs.get(0); <START> Map<String, List<T>> childrenForParent = new LinkedHashMap<>(nodeAdapter.getNamedChildren(firstBreadcrumb.getNode())); <END> NodeLocation locationInParent = firstBreadcrumb.getLocation(); int ix = locationInParent.getIndex(); String name = locationInParent.getName(); List<T> childList = new ArrayList<>(childrenForParent.get(name)); switch (modificationType) { case REPLACE: childList.set(ix, curNode); break; case DELETE: childList.remove(ix); break; case INSERT_BEFORE: childList.add(ix, curNode); break; case INSERT_AFTER: childList.add(ix + 1, curNode); break; } childrenForParent.put(name, childList); curNode = nodeAdapter.withNewChildren(firstBreadcrumb.getNode(), childrenForParent); if (breadcrumbs.size() == 1) { return curNode; } for (Breadcrumb<T> breadcrumb : breadcrumbs.subList(1, breadcrumbs.size())) { Map<String, List<T>> newChildren = new LinkedHashMap<>(nodeAdapter.getNamedChildren(breadcrumb.getNode())); final T newChild = curNode; NodeLocation location = breadcrumb.getLocation(); List<T> list = new ArrayList<>(newChildren.get(location.getName())); list.set(location.getIndex(), newChild); newChildren.put(location.getName(), list); curNode = nodeAdapter.withNewChildren(breadcrumb.getNode(), newChildren); } return curNode; }</code><technical_language>Linked hasmap require ? set node new children - order of children matter is this a step far</technical_language>

Target:
public T toRoot() { if (breadcrumbs.size() == 0 && modificationType != ModificationType.DELETE) { return this.curNode; } if (breadcrumbs.size() == 0 && modificationType == ModificationType.DELETE) { return null; } T curNode = this.curNode; Breadcrumb<T> firstBreadcrumb = breadcrumbs.get(0); Map<String, List<T>> childrenForParent = new HashMap<>(nodeAdapter.getNamedChildren(firstBreadcrumb.getNode())); NodeLocation locationInParent = firstBreadcrumb.getLocation(); int ix = locationInParent.getIndex(); String name = locationInParent.getName(); List<T> childList = new ArrayList<>(childrenForParent.get(name)); switch (modificationType) { case REPLACE: childList.set(ix, curNode); break; case DELETE: childList.remove(ix); break; case INSERT_BEFORE: childList.add(ix, curNode); break; case INSERT_AFTER: childList.add(ix + 1, curNode); break; } childrenForParent.put(name, childList); curNode = nodeAdapter.withNewChildren(firstBreadcrumb.getNode(), childrenForParent); if (breadcrumbs.size() == 1) { return curNode; } for (Breadcrumb<T> breadcrumb : breadcrumbs.subList(1, breadcrumbs.size())) { Map<String, List<T>> newChildren = new LinkedHashMap<>(nodeAdapter.getNamedChildren(breadcrumb.getNode())); final T newChild = curNode; NodeLocation location = breadcrumb.getLocation(); List<T> list = new ArrayList<>(newChildren.get(location.getName())); list.set(location.getIndex(), newChild); newChildren.put(location.getName(), list); curNode = nodeAdapter.withNewChildren(breadcrumb.getNode(), newChildren); } return curNode; }