/** * Returns a modifiable {@link List} of child nodes of <strong>first</strong> subtree. * * @return a modifiable {@link List} of child nodes of <strong>first</strong> subtree */ @Override protected List<SpanNode> children() { return children(0); }
public int numChildren(int i) { return children(i).size(); }
/** * Convenience method to add a span node to the child tree at index i. This is equivalent to calling * <code> * AlternateSpanList.children(i).add(node); * </code> * * @param i index * @param node span node */ public AlternateSpanList add(int i, SpanNode node) { checkValidity(node, children(i)); node.setParent(this); children(i).add(node); return this; }
/** * Returns the text covered by this span as given by subtree i, or null if subtree i is empty. * * @param i the index of the subtree to use * @param text the text to get a substring from * @return the text covered by this span as given by subtree i, or null if subtree i is empty */ public CharSequence getText(int i, CharSequence text) { if (children(i).isEmpty()) { return null; } StringBuilder str = new StringBuilder(); List<SpanNode> ch = children(i); for (SpanNode node : ch) { CharSequence childText = node.getText(text); if (childText != null) { str.append(node.getText(text)); } } return str; }
/** * 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 * @throws IllegalArgumentException if the given node is not a child of this SpanList */ public void move(int i, SpanNode node, SpanList target) { boolean removed = children(i).remove(node); if (removed) { //we found the node node.setParent(null); resetCachedFromAndTo(); target.add(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 * @throws IndexOutOfBoundsException if the given index is out of range */ public void move(int i, int nodeNum, SpanList target) { SpanNode node = children(i).remove(nodeNum); if (node != null) { //we found the node node.setParent(null); resetCachedFromAndTo(); target.add(node); } }
/** * 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); } }