@Test public void testRemoveAll() { String messageRemoveExpected = "The tree node was expected to be removed, but actually was not"; String messageRemoveResultTrueExpected = "The tree node remove result was expected to be true, but actually was false"; Collection<TreeNode<String>> mNodesToRemove1 = new ArrayList<>(3); mNodesToRemove1.add(node6); mNodesToRemove1.add(node7); mNodesToRemove1.add(node10); assertTrue(messageRemoveResultTrueExpected, root.removeAll(mNodesToRemove1)); assertFalse(messageRemoveExpected, root.contains(node6)); assertFalse(messageRemoveExpected, root.contains(node7)); assertFalse(messageRemoveExpected, root.contains(node10)); Collection<TreeNode<String>> mNodesToRemove2 = Collections.singletonList(node4); assertTrue(messageRemoveResultTrueExpected, node2.removeAll(mNodesToRemove2)); assertFalse(messageRemoveExpected, node2.contains(node4)); assertFalse(messageRemoveExpected, node3.contains(node4)); Collection<TreeNode<String>> mNodesToRemove3 = new ArrayList<>(2); mNodesToRemove3.add(node8); mNodesToRemove3.add(anotherNode); assertTrue(messageRemoveResultTrueExpected, node2.removeAll(mNodesToRemove3)); assertFalse(messageRemoveResultTrueExpected, node2.contains(node8)); assertFalse(messageRemoveResultTrueExpected, root.contains(node8)); String messageRemoveResultFalseExpected = "The tree node remove result was expected to be false, but actually was true"; assertFalse(root.contains(node7)); Collection<TreeNode<String>> mNodesToRemove4 = new ArrayList<>(2); mNodesToRemove4.add(node7); mNodesToRemove4.add(anotherNode); assertFalse(messageRemoveResultFalseExpected, root.removeAll(mNodesToRemove4)); assertFalse(messageRemoveResultFalseExpected, node1.removeAll(mNodesToRemove4)); assertFalse(messageRemoveResultFalseExpected, node2.removeAll(null)); assertFalse(messageRemoveResultFalseExpected, root.removeAll(Collections.<TreeNode<String>>emptyList())); }
public boolean removeAll(Collection<TreeNode<T>> nodes) { if (isLeaf() || areAllNulls(nodes)) { return false; } boolean result = false; for (TreeNode<T> node : nodes) { boolean currentResult = remove(node); if (!result && currentResult) { result = true; } } return result; }
TreeNode implements Iterable<TreeNode<T>>, Serializable, Cloneable { public boolean removeAll(Collection<TreeNode<T>> nodes) { if (isLeaf() || areAllNulls(nodes)) { return false; } boolean result = false; for (TreeNode<T> node : nodes) { boolean currentResult = remove(node); if (!result && currentResult) { result = true; } } return result; } }
TreeNode implements Iterable<TreeNode<T>>, Serializable, Cloneable { public boolean removeAll(Collection<TreeNode<T>> nodes) { if (isLeaf() || areAllNulls(nodes)) { return false; } boolean result = false; for (TreeNode<T> node : nodes) { boolean currentResult = remove(node); if (!result && currentResult) { result = true; } } return result; } TreeNode(T data);  TreeNode(); }
TreeNode implements Iterable<TreeNode<T>>, Serializable, Cloneable { public boolean removeAll(Collection<TreeNode<T>> nodes) { if (isLeaf() || areAllNulls(nodes)) { return false; } boolean result = false; for (TreeNode<T> node : nodes) { boolean currentResult = remove(node); if (!result && currentResult) { result = true; } } return result; } TreeNode(T data);  TreeNode(); abstract Collection<? extends TreeNode<T>> subtrees(); abstract boolean add(TreeNode<T> subtree); abstract boolean dropSubtree(TreeNode<T> subtree); abstract void clear(); abstract TreeNodeIterator iterator(); T data(); void setData(T data); boolean isRoot(); TreeNode<T> root(); TreeNode<T> parent(); boolean isLeaf(); @SuppressWarnings("unchecked") TreeNode<T> find(final T data); Collection<? extends TreeNode<T>> findAll(final T data); boolean hasSubtree(TreeNode<T> subtree); boolean contains(TreeNode<T> node); boolean containsAll(Collection<TreeNode<T>> nodes); boolean remove(TreeNode<T> node); boolean removeAll(Collection<TreeNode<T>> nodes); void traversePreOrder(TraversalAction<TreeNode<T>> action); void traversePostOrder(TraversalAction<TreeNode<T>> action); Collection<TreeNode<T>> preOrdered(); Collection<TreeNode<T>> postOrdered(); Collection<? extends TreeNode<T>> path(TreeNode<T> descendant); TreeNode<T> commonAncestor(TreeNode<T> node); boolean isSiblingOf(TreeNode<T> node); boolean isAncestorOf(TreeNode<T> node); boolean isDescendantOf(TreeNode<T> node); long size(); int height(); int level(); @SuppressWarnings("unchecked") @Override TreeNode<T> clone(); @SuppressWarnings("unchecked") @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
TreeNode implements Iterable<TreeNode<T>>, Serializable, Cloneable { public boolean removeAll(Collection<TreeNode<T>> nodes) { if (isLeaf() || areAllNulls(nodes)) { return false; } boolean result = false; for (TreeNode<T> node : nodes) { boolean currentResult = remove(node); if (!result && currentResult) { result = true; } } return result; } TreeNode(T data);  TreeNode(); abstract Collection<? extends TreeNode<T>> subtrees(); abstract boolean add(TreeNode<T> subtree); abstract boolean dropSubtree(TreeNode<T> subtree); abstract void clear(); abstract TreeNodeIterator iterator(); T data(); void setData(T data); boolean isRoot(); TreeNode<T> root(); TreeNode<T> parent(); boolean isLeaf(); @SuppressWarnings("unchecked") TreeNode<T> find(final T data); Collection<? extends TreeNode<T>> findAll(final T data); boolean hasSubtree(TreeNode<T> subtree); boolean contains(TreeNode<T> node); boolean containsAll(Collection<TreeNode<T>> nodes); boolean remove(TreeNode<T> node); boolean removeAll(Collection<TreeNode<T>> nodes); void traversePreOrder(TraversalAction<TreeNode<T>> action); void traversePostOrder(TraversalAction<TreeNode<T>> action); Collection<TreeNode<T>> preOrdered(); Collection<TreeNode<T>> postOrdered(); Collection<? extends TreeNode<T>> path(TreeNode<T> descendant); TreeNode<T> commonAncestor(TreeNode<T> node); boolean isSiblingOf(TreeNode<T> node); boolean isAncestorOf(TreeNode<T> node); boolean isDescendantOf(TreeNode<T> node); long size(); int height(); int level(); @SuppressWarnings("unchecked") @Override TreeNode<T> clone(); @SuppressWarnings("unchecked") @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }