@Override public String toString() { return "AlternateSpanList, num subtrees=" + getNumSubTrees(); }
public void write(AlternateSpanList altSpanList) { buf.put(AlternateSpanList.ID); buf.putInt1_2_4Bytes(altSpanList.getNumSubTrees()); for (int i = 0; i < altSpanList.getNumSubTrees(); i++) { buf.putDouble(altSpanList.getProbability(i)); buf.putInt1_2_4Bytes(altSpanList.numChildren(i)); Iterator<SpanNode> children = altSpanList.childIterator(i); while (children.hasNext()) { write(children.next()); } } }
public void write(AlternateSpanList altSpanList) { buf.put(AlternateSpanList.ID); buf.putInt1_2_4Bytes(altSpanList.getNumSubTrees()); for (int i = 0; i < altSpanList.getNumSubTrees(); i++) { buf.putDouble(altSpanList.getProbability(i)); buf.putInt1_2_4Bytes(altSpanList.numChildren(i)); Iterator<SpanNode> children = altSpanList.childIterator(i); while (children.hasNext()) { write(children.next()); } } }
/** * Moves a child of this SpanList to another SpanList. * * @param node the node to move * @param target the SpanList to add the node to * @param targetSubTree the index of the subtree of the given AlternateSpanList to add the node to * @throws IllegalArgumentException if the given node is not a child of this SpanList * @throws IndexOutOfBoundsException if the target subtree index is out of range */ public void move(SpanNode node, AlternateSpanList target, int targetSubTree) { if (targetSubTree < 0 || targetSubTree >= target.getNumSubTrees()) { throw new IndexOutOfBoundsException(target + " has no subtree at index " + targetSubTree); } boolean removed = children().remove(node); if (removed) { //we found the node node.setParent(null); resetCachedFromAndTo(); target.add(targetSubTree, node); } else { throw new IllegalArgumentException("Node " + node + " is not a child of this SpanList, cannot move."); } }
/** * Moves a child of this SpanList to another SpanList. * * @param i the index of the subtree to remove the node from * @param node the node to move * @param target the SpanList to add the node to * @param targetSubTree the index of the subtree of the given AlternateSpanList to add the node to * @throws IllegalArgumentException if the given node is not a child of this SpanList * @throws IndexOutOfBoundsException if the given index is out of range, or if the target subtree index is out of range */ public void move(int i, SpanNode node, AlternateSpanList target, int targetSubTree) { if (targetSubTree < 0 || targetSubTree >= target.getNumSubTrees()) { throw new IndexOutOfBoundsException(target + " has no subtree at index " + targetSubTree); } boolean removed = children(i).remove(node); if (removed) { //we found the node node.setParent(null); resetCachedFromAndTo(); target.add(targetSubTree, node); } else { throw new IllegalArgumentException("Node " + node + " is not a child of this SpanList, cannot move."); } }
/** * Moves a child of this SpanList to another SpanList. * * @param i the index of the subtree to remove the node from * @param nodeNum the index of the node to move * @param target the SpanList to add the node to * @param targetSubTree the index of the subtree of the given AlternateSpanList to add the node to * @throws IndexOutOfBoundsException if any of the given indeces are out of range, or the target subtree index is out of range */ public void move(int i, int nodeNum, AlternateSpanList target, int targetSubTree) { if (targetSubTree < 0 || targetSubTree >= target.getNumSubTrees()) { throw new IndexOutOfBoundsException(target + " has no subtree at index " + targetSubTree); } SpanNode node = children(i).remove(nodeNum); if (node != null) { //we found the node node.setParent(null); resetCachedFromAndTo(); target.add(targetSubTree, node); } }
/** * Moves a child of this SpanList to another SpanList. * * @param nodeNum the index of the node to move * @param target the SpanList to add the node to * @param targetSubTree the index of the subtree of the given AlternateSpanList to add the node to * @throws IndexOutOfBoundsException if the given index is out of range, or the target subtree index is out of range */ public void move(int nodeNum, AlternateSpanList target, int targetSubTree) { if (targetSubTree < 0 || targetSubTree >= target.getNumSubTrees()) { throw new IndexOutOfBoundsException(target + " has no subtree at index " + targetSubTree); } SpanNode node = children().remove(nodeNum); if (node != null) { //we found the node node.setParent(null); resetCachedFromAndTo(); target.add(targetSubTree, node); } }