/** * Append a child to this node and return the child. * * @param child the child to append. * @return <code>child</code> */ public Node appendChild(Node child) { child.detach(); child.setParentNode(this); if (firstChild == null) { firstChild = child; } else { lastChild.setNextSibling(child); } lastChild = child; return child; }
/** * Append a child to this node and return the child. * * @param child the child to append. * @return <code>child</code> */ public Node appendChild(Node child) { child.detach(); child.setParentNode(this); if (firstChild == null) { firstChild = child; } else { lastChild.setNextSibling(child); } lastChild = child; return child; }
/** * Append a child to this node and return the child. * * @param child the child to append. * @return <code>child</code> */ public Node appendChild(Node child) { child.detach(); child.setParentNode(this); if (firstChild == null) { firstChild = child; } else { lastChild.setNextSibling(child); } lastChild = child; 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; }
/** * 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; }
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; }
/** * Append the children of another node to this node removing them from the other node . * @param parent the other node whose children to append to this one */ public void appendChildren(Node parent) { Node child = parent.getFirstChild(); if (child == null) { return; } ParentNode another = (ParentNode) parent; if (firstChild == null) { firstChild = child; } else { lastChild.setNextSibling(child); } lastChild = another.lastChild; do { child.setParentNode(this); } while ((child = child.getNextSibling()) != null); another.firstChild = null; another.lastChild = null; }
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; }
/** * Append the children of another node to this node removing them from the other node . * @param parent the other node whose children to append to this one */ public void appendChildren(Node parent) { Node child = parent.getFirstChild(); if (child == null) { return; } ParentNode another = (ParentNode) parent; if (firstChild == null) { firstChild = child; } else { lastChild.setNextSibling(child); } lastChild = another.lastChild; do { child.setParentNode(this); } while ((child = child.getNextSibling()) != null); another.firstChild = null; another.lastChild = null; }
/** * Append the children of another node to this node removing them from the other node . * @param parent the other node whose children to append to this one */ public void appendChildren(Node parent) { Node child = parent.getFirstChild(); if (child == null) { return; } ParentNode another = (ParentNode) parent; if (firstChild == null) { firstChild = child; } else { lastChild.setNextSibling(child); } lastChild = another.lastChild; do { child.setParentNode(this); } while ((child = child.getNextSibling()) != null); another.firstChild = null; another.lastChild = null; }
/** * 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; } } } }