/** * Removes all subtrees (both the subtrees themselves and their contents, which become invalidated). * Note that a new empty subtree is automatically added at index 0, since an AlternateSpanList always has at * least one subtree. */ public void removeChildren() { for (Children ch : childTrees) { ch.setInvalid(); ch.setParent(null); ch.clearChildren(); } childTrees.clear(); resetCachedFromAndTo(); ensureAtLeastOneSubTree(); }
/** * Sets the subtree at index i. * * @param i the index of where to set the subtree * @param subtree the subtree to set * @param probability the probability to set * @return the overwritten subtree, if any */ public List<SpanNode> setChildren(int i, List<SpanNode> subtree, double probability) { resetCachedFromAndTo(); if (childTrees.size() == 1 && i == 0) { //replace the first subtree Children sub = new Children(getParent(), subtree, probability); Children retval = childTrees.set(i, sub); if (retval == null) { return null; } else { retval.setParent(null); for (SpanNode node : retval.children()) { node.setParent(null); } return retval.children(); } } List<SpanNode> retval = removeChildren(i); addChildren(i, subtree, probability); return retval; }
/** * Removes the subtree at index i (both the subtree itself and its contents, which become invalidated). * Note that if this AlternateSpanList has only one subtree and index 0 is given, * a new empty subtree is automatically added, since an AlternateSpanList always has at least one subtree. * * @param i the index of the subtree to remove * @return the subtree removed, if any (note: invalidated) */ public List<SpanNode> removeChildren(int i) { Children retval = childTrees.remove(i); ensureAtLeastOneSubTree(); resetCachedFromAndTo(); if (retval != null) { retval.setInvalid(); retval.setParent(null); for (SpanNode node : retval.children()) { node.setParent(null); } return retval.children(); } return null; }
private Children(SpanNodeParent parent) { setParent(parent); }
@Override void setParent(SpanNodeParent parent) { super.setParent(parent); for (Children ch : childTrees) { ch.setParent(parent); } }
private Children(SpanNodeParent parent, List<SpanNode> children, double probability) { super(children); setParent(parent); if (children != null) { for (SpanNode node : children) { node.setParent(AlternateSpanList.this); } } this.probability = probability; }