MultiTreeNode extends TreeNode<T> { public boolean dropSubtrees(Collection<? extends MultiTreeNode<T>> subtrees) { if (isLeaf() || areAllNulls(subtrees)) { return false; } boolean result = false; for (MultiTreeNode<T> subtree : subtrees) { boolean currentResult = dropSubtree(subtree); if (!result && currentResult) { result = true; } } return result; } MultiTreeNode(T data); boolean addSubtrees(Collection<? extends MultiTreeNode<T>> subtrees); Collection<? extends MultiTreeNode<T>> siblings(); boolean hasSubtrees(Collection<? extends MultiTreeNode<T>> subtrees); boolean dropSubtrees(Collection<? extends MultiTreeNode<T>> subtrees);  }
@Test public void testDropSubtrees() { String messageRemoveExpected = "The specified subtree was expected to be dropped, but actually was not"; String messageRemoveResultTrue = "The subtrees removal result was expected to be true, but actually was false"; Collection<MultiTreeNode<String>> mSubtreesToRemove1 = new ArrayList<>(3); mSubtreesToRemove1.add((MultiTreeNode<String>) node3); mSubtreesToRemove1.add((MultiTreeNode<String>) node7); mSubtreesToRemove1.add((MultiTreeNode<String>) node8); assertTrue(messageRemoveResultTrue, ((MultiTreeNode<String>) node2).dropSubtrees(mSubtreesToRemove1)); assertFalse(messageRemoveExpected, node2.hasSubtree(node3)); assertFalse(messageRemoveExpected, node2.hasSubtree(node7)); assertFalse(messageRemoveExpected, node2.hasSubtree(node8)); Collection<MultiTreeNode<String>> mSubtreesToRemove2 = new ArrayList<>(2); mSubtreesToRemove2.add((MultiTreeNode<String>) node9); mSubtreesToRemove2.add((MultiTreeNode<String>) anotherNode); assertTrue(messageRemoveResultTrue, ((MultiTreeNode<String>) root).dropSubtrees(mSubtreesToRemove2)); assertFalse(messageRemoveExpected, root.contains(node9)); String messageRemoveResultFalse = "The subtrees removal result was expected to be false, but actually was true"; assertFalse(messageRemoveResultFalse, ((MultiTreeNode<String>) node1).dropSubtrees(Collections.singletonList((MultiTreeNode<String>) node2))); assertFalse(messageRemoveResultFalse, ((MultiTreeNode<String>) root).dropSubtrees(Collections.<MultiTreeNode<String>>emptyList())); assertFalse(messageRemoveResultFalse, ((MultiTreeNode<String>) node1).dropSubtrees(Collections.<MultiTreeNode<String>>singletonList(null))); }