+ public void addChild(Node child) {
+ children.add(child);
+ usedByNonDoomedNode += child.state().doomed ? 0 : 1;
+ }
+ public void removeChild(Node child) {
+ if (!children.contains(child)) return;
+ children.remove(child);
+ usedByNonDoomedNode -= child.state().doomed ? 0 : 1;
+ check();
+ }
+
+ public boolean usedByAnyNode() { return children.size() > 0; }
+ public boolean usedByNonDoomedNode() { return usedByNonDoomedNode > 0; }
+
+ public String toString() { return super.toString()+"->"+parent(); }
+
+ public void check() { if (children.size()==0) destroy(); }
+ public void destroy() {
+ if (destroyed) return;
+ if (parent==null) return; // never destroy the "primordeal" result
+ destroyed = true;
+ parent.removeChild(this);
+ while(children.size() > 0)
+ for(Node n : children) {
+ removeChild(n);
+ n.removeResult(this);
+ break;
+ }
+ }