public Node insertBetween(Node child, Node prev, Node next) { assert prev == null || this == prev.getParentNode(); assert next == null || this == next.getParentNode(); assert prev != null || next == firstChild; assert next != null || prev == lastChild; assert prev == null || next == null || prev.getNextSibling() == next; if (next == null) { return appendChild(child); } child.detach(); child.setParentNode(this); child.setNextSibling(next); if (prev == null) { firstChild = child; } else { prev.setNextSibling(child); } return child; }
public Node insertBetween(Node child, Node prev, Node next) { assert prev == null || this == prev.getParentNode(); assert next == null || this == next.getParentNode(); assert prev != null || next == firstChild; assert next != null || prev == lastChild; assert prev == null || next == null || prev.getNextSibling() == next; if (next == null) { return appendChild(child); } child.detach(); child.setParentNode(this); child.setNextSibling(next); if (prev == null) { firstChild = child; } else { prev.setNextSibling(child); } return child; }
public Node insertBetween(Node child, Node prev, Node next) { assert prev == null || this == prev.getParentNode(); assert next == null || this == next.getParentNode(); assert prev != null || next == firstChild; assert next != null || prev == lastChild; assert prev == null || next == null || prev.getNextSibling() == next; if (next == null) { return appendChild(child); } child.detach(); child.setParentNode(this); child.setNextSibling(next); if (prev == null) { firstChild = child; } else { prev.setNextSibling(child); } return child; }
break; current = current.getParentNode();
break; current = current.getParentNode();
break; current = current.getParentNode();
/** * Remove a child from this node. * @param node the child to remove */ void removeChild(Node node) { assert this == node.getParentNode(); if (firstChild == node) { firstChild = node.getNextSibling(); if (lastChild == node) { lastChild = null; } } else { Node prev = firstChild; Node next = firstChild.getNextSibling(); while (next != node) { prev = next; next = next.getNextSibling(); } prev.setNextSibling(node.getNextSibling()); if (lastChild == node) { lastChild = prev; } } } }
/** * Remove a child from this node. * @param node the child to remove */ void removeChild(Node node) { assert this == node.getParentNode(); if (firstChild == node) { firstChild = node.getNextSibling(); if (lastChild == node) { lastChild = null; } } else { Node prev = firstChild; Node next = firstChild.getNextSibling(); while (next != node) { prev = next; next = next.getNextSibling(); } prev.setNextSibling(node.getNextSibling()); if (lastChild == node) { lastChild = prev; } } } }
/** * Remove a child from this node. * @param node the child to remove */ void removeChild(Node node) { assert this == node.getParentNode(); if (firstChild == node) { firstChild = node.getNextSibling(); if (lastChild == node) { lastChild = null; } } else { Node prev = firstChild; Node next = firstChild.getNextSibling(); while (next != node) { prev = next; next = next.getNextSibling(); } prev.setNextSibling(node.getNextSibling()); if (lastChild == node) { lastChild = prev; } } } }
/** * Insert a new child before a pre-existing child and return the newly inserted child. * @param child the new child * @param sibling the existing child before which to insert (must be a child of this node) or <code>null</code> to append * @return <code>child</code> */ public Node insertBefore(Node child, Node sibling) { assert sibling == null || this == sibling.getParentNode(); if (sibling == null) { return appendChild(child); } child.detach(); child.setParentNode(this); if (firstChild == sibling) { child.setNextSibling(sibling); firstChild = child; } else { Node prev = firstChild; Node next = firstChild.getNextSibling(); while (next != sibling) { prev = next; next = next.getNextSibling(); } prev.setNextSibling(child); child.setNextSibling(next); } return child; }
/** * Insert a new child before a pre-existing child and return the newly inserted child. * @param child the new child * @param sibling the existing child before which to insert (must be a child of this node) or <code>null</code> to append * @return <code>child</code> */ public Node insertBefore(Node child, Node sibling) { assert sibling == null || this == sibling.getParentNode(); if (sibling == null) { return appendChild(child); } child.detach(); child.setParentNode(this); if (firstChild == sibling) { child.setNextSibling(sibling); firstChild = child; } else { Node prev = firstChild; Node next = firstChild.getNextSibling(); while (next != sibling) { prev = next; next = next.getNextSibling(); } prev.setNextSibling(child); child.setNextSibling(next); } return child; }
/** * Insert a new child before a pre-existing child and return the newly inserted child. * @param child the new child * @param sibling the existing child before which to insert (must be a child of this node) or <code>null</code> to append * @return <code>child</code> */ public Node insertBefore(Node child, Node sibling) { assert sibling == null || this == sibling.getParentNode(); if (sibling == null) { return appendChild(child); } child.detach(); child.setParentNode(this); if (firstChild == sibling) { child.setNextSibling(sibling); firstChild = child; } else { Node prev = firstChild; Node next = firstChild.getNextSibling(); while (next != sibling) { prev = next; next = next.getNextSibling(); } prev.setNextSibling(child); child.setNextSibling(next); } return child; }