/** * 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; }
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; }
/** * 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; }