/** * Detach this child from its parent. * <p> * Equivalent to {@code setParent(null)}. */ public default void detach() { setParent(null); } }
/** * Adds a child to this parent. * <p> * If possible, child current parent is changed to this node. * * @param <C> Type of the child. * @param child The child. <em>MUST NOT</em> be null. * @return The input {@code child}. * @throws IllegalArgumentException If {@code child} is {@code null}. * @throws IllegalStateException If {@code child}'s parent can not be set. */ public default <C extends Child> C addChild(C child) { Checks.isNotNull(child, "child"); // setParent calls canAddChild() child.setParent(this); return child; }
/** * Remove a child. * <p> * If child is not a child of this parent, then false is returned. * * @param child The child. * @return {@code true} if child was removed, {@code false} otherwise. */ public default boolean removeChild(Child child) { if (child != null && child.getParent() == this) { getModifiableChildren().remove(child); child.setParent(null); return true; } else { return false; } }