/** Removes all children. */ @Override public void removeChildren() { final long removed = childrenCost(); if (removed != 0) { SelectedNode parent = this; do { parent.cost -= removed; } while ((parent = (SelectedNode) parent.getParent()) != null); } super.removeChildren(); }
/** * Adds the given tile as a child of this tile. * * @throws ClassCastException if the given child is not an instance of {@code SelectedNode}. This * is an intentional restriction in order to avoid more subtile bugs later. */ @Override public void addChild(final TreeNode child) throws ClassCastException { super.addChild(child); if (child != null) { final long added = ((SelectedNode) child).cost; if (added != 0) { SelectedNode parent = this; do { parent.cost += added; } while ((parent = (SelectedNode) parent.getParent()) != null); } } }