/** * 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; }