@Override public void add(SpanNode spanNode) { returnedFromNext = null; owner.resetCachedFromAndTo(); base.add(spanNode); } }
@Override public void remove() { if (returnedFromNext != null) { returnedFromNext.setInvalid(); returnedFromNext.setParent(null); owner.resetCachedFromAndTo(); } returnedFromNext = null; base.remove(); }
@Override public void set(SpanNode spanNode) { if (returnedFromNext != null) { returnedFromNext.setInvalid(); returnedFromNext.setParent(null); } owner.resetCachedFromAndTo(); returnedFromNext = null; base.set(spanNode); }
void resetCachedFromAndTo() { cachedFrom = Integer.MIN_VALUE; cachedTo = Integer.MIN_VALUE; if (getParent() instanceof SpanList) { ((SpanList) getParent()).resetCachedFromAndTo(); } }
/** * Moves a child of this SpanList to another SpanList. * * @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(SpanNode node, SpanList target) { boolean removed = children().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."); } }
/** * Removes and invalidates the given SpanNode from this. * * @param node the node to remove. * @return this, for chaining. */ public SpanList remove(SpanNode node) { boolean removed = children().remove(node); if (removed) { node.setParent(null); resetCachedFromAndTo(); node.setInvalid(); } return this; }
/** * 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 * @throws IndexOutOfBoundsException if the given index is out of range */ public void move(int nodeNum, SpanList target) { SpanNode node = children().remove(nodeNum); if (node != null) { //we found the node node.setParent(null); resetCachedFromAndTo(); target.add(node); } }
/** Removes and invalidates all references to child nodes. */ public void clearChildren() { for (SpanNode node : children()) { node.setInvalid(); node.setParent(null); } children().clear(); resetCachedFromAndTo(); }
/** * 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); } }
/** * 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."); } }
/** * Adds a child node to this SpanList. * * @param node the node to add. * @return this, for call chaining * @throws IllegalStateException if SpanNode.isValid() returns false. */ public SpanList add(SpanNode node) { checkValidity(node, children()); node.setParent(this); resetCachedFromAndTo(); children().add(node); return this; }