@Test public void testContainsAll() { String messageContainExpected = "The tree was expected to contain all of the specified nodes, but actually was not"; Collection<TreeNode<String>> mTreeNodesContain1 = new ArrayList<>(2); mTreeNodesContain1.add(node3); mTreeNodesContain1.add(node6); assertTrue(messageContainExpected, node2.containsAll(mTreeNodesContain1)); Collection<TreeNode<String>> mTreeNodesContain2 = new ArrayList<>(6); mTreeNodesContain2.add(node8); mTreeNodesContain2.add(node7); mTreeNodesContain2.add(node1); mTreeNodesContain2.add(node9); mTreeNodesContain2.add(node10); mTreeNodesContain2.add(node6); assertTrue(messageContainExpected, root.containsAll(mTreeNodesContain2)); List<TreeNode<String>> mTreeNodesContain3 = Collections.singletonList(node3); assertTrue(messageContainExpected, node2.containsAll(mTreeNodesContain3)); String messageContainNotExpected = "The tree was not expected to contain all of the specified nodes, but actually was"; Collection<TreeNode<String>> mTreeNodesNotContain1 = new ArrayList<>(3); mTreeNodesNotContain1.add(node5); mTreeNodesNotContain1.add(node10); mTreeNodesNotContain1.add(anotherNode); assertFalse(messageContainNotExpected, node1.containsAll(mTreeNodesNotContain1)); assertFalse(messageContainNotExpected, root.containsAll(mTreeNodesNotContain1)); Collection<TreeNode<String>> mTreeNodesNotContain2 = new ArrayList<>(2); mTreeNodesNotContain2.add(root); mTreeNodesNotContain2.add(node2); assertFalse(messageContainNotExpected, root.containsAll(mTreeNodesNotContain2)); Collection<TreeNode<String>> mTreeNodesNotContain3 = new ArrayList<>(2); mTreeNodesNotContain3.add(node6); mTreeNodesNotContain3.add(anotherNode); assertFalse(messageContainNotExpected, node3.containsAll(mTreeNodesNotContain3)); assertFalse(messageContainNotExpected, root.containsAll(null)); assertFalse(messageContainNotExpected, node3.containsAll(Collections.<TreeNode<String>>emptyList())); }
public boolean containsAll(Collection<TreeNode<T>> nodes) { if (isLeaf() || areAllNulls(nodes)) { return false; } for (TreeNode<T> node : nodes) { if (!contains(node)) { return false; } } return true; }
TreeNode implements Iterable<TreeNode<T>>, Serializable, Cloneable { public boolean containsAll(Collection<TreeNode<T>> nodes) { if (isLeaf() || areAllNulls(nodes)) { return false; } for (TreeNode<T> node : nodes) { if (!contains(node)) { return false; } } return true; } }
TreeNode implements Iterable<TreeNode<T>>, Serializable, Cloneable { public boolean containsAll(Collection<TreeNode<T>> nodes) { if (isLeaf() || areAllNulls(nodes)) { return false; } for (TreeNode<T> node : nodes) { if (!contains(node)) { return false; } } return true; } TreeNode(T data);  TreeNode(); }
TreeNode implements Iterable<TreeNode<T>>, Serializable, Cloneable { public boolean containsAll(Collection<TreeNode<T>> nodes) { if (isLeaf() || areAllNulls(nodes)) { return false; } for (TreeNode<T> node : nodes) { if (!contains(node)) { return false; } } return true; } 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 containsAll(Collection<TreeNode<T>> nodes) { if (isLeaf() || areAllNulls(nodes)) { return false; } for (TreeNode<T> node : nodes) { if (!contains(node)) { return false; } } return true; } 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();  }