/** * Detaches all element children from a node. * @param node Must not be null. * @return True iff any element children were detached by this call. */ public boolean removeAllElementChildren(final Node node) { final boolean hadChildren = node.lastChild != null; while (node.lastChild != null) { node.removeChild(node.lastChild); } return hadChildren; }
/** * Detaches all element children from a node. * @param node Must not be null. * @return True iff any element children were detached by this call. */ public boolean removeAllElementChildren(final Node node) { final boolean hadChildren = node.lastChild != null; while (node.lastChild != null) { node.removeChild(node.lastChild); } return hadChildren; }
public static void remove(final Node element) { element.parentNode.removeChild(element); } }
public static void remove(final Node element) { element.parentNode.removeChild(element); } }
@Override public void remove() { if (last == null) { throw new IllegalStateException(); } parent.removeChild(last); last = null; } }
/** * Removes the child from parent if both parent and child are not null and parent contains child. * * @return {@code true} if the the element has been removed from its parent, {@code false} otherwise. */ public static boolean failSafeRemove(Node parent, Element child) { //noinspection SimplifiableIfStatement if (parent != null && child != null && parent.contains(child)) { return parent.removeChild(child) != null; } return false; }
@Test public void testRemove() { final Node node = mock(Node.class); final Node parentNode = mock(Node.class); node.parentNode = parentNode; ElementHelper.remove(node); verify(parentNode).removeChild(node); } }
@Test public void testRemove() { final Node node = mock(Node.class); final Node parentNode = mock(Node.class); node.parentNode = parentNode; ElementHelper.remove(node); verify(parentNode).removeChild(node); } }