@Test public void testSiblings() { String message = "Tree node siblings were incorrectly determined"; Collection<TreeNode<String>> mSiblingsLevel1 = new HashSet<>(2); mSiblingsLevel1.add(node2); mSiblingsLevel1.add(node9); Collection<TreeNode<String>> mSiblingsLevel2 = new HashSet<>(2); mSiblingsLevel2.add(node3); mSiblingsLevel2.add(node7); assertEquals(message, mSiblingsLevel1, ((MultiTreeNode<String>) node1).siblings()); assertEquals(message, mSiblingsLevel2, ((MultiTreeNode<String>) node8).siblings()); assertEquals(message, Collections.emptySet(), ((MultiTreeNode<String>) node6).siblings()); }
public Collection<? extends MultiTreeNode<T>> siblings() { if (isRoot()) { String message = String.format("Unable to find the siblings. The tree node %1$s is root", root()); throw new TreeNodeException(message); } Collection<? extends TreeNode<T>> parentSubtrees = parent.subtrees(); int parentSubtreesSize = parentSubtrees.size(); if (parentSubtreesSize == 1) { return Collections.emptySet(); } Collection<MultiTreeNode<T>> siblings = new HashSet<>(parentSubtreesSize - 1); for (TreeNode<T> parentSubtree : parentSubtrees) { if (!parentSubtree.equals(this)) { siblings.add((MultiTreeNode<T>) parentSubtree); } } return siblings; }
MultiTreeNode extends TreeNode<T> { public Collection<? extends MultiTreeNode<T>> siblings() { if (isRoot()) { String message = String.format("Unable to find the siblings. The tree node %1$s is root", root()); throw new TreeNodeException(message); } Collection<? extends TreeNode<T>> parentSubtrees = parent.subtrees(); int parentSubtreesSize = parentSubtrees.size(); if (parentSubtreesSize == 1) { return Collections.emptySet(); } Collection<MultiTreeNode<T>> siblings = new HashSet<>(parentSubtreesSize - 1); for (TreeNode<T> parentSubtree : parentSubtrees) { if (!parentSubtree.equals(this)) { siblings.add((MultiTreeNode<T>) parentSubtree); } } return siblings; } }
MultiTreeNode extends TreeNode<T> { public Collection<? extends MultiTreeNode<T>> siblings() { if (isRoot()) { String message = String.format("Unable to find the siblings. The tree node %1$s is root", root()); throw new TreeNodeException(message); } Collection<? extends TreeNode<T>> parentSubtrees = parent.subtrees(); int parentSubtreesSize = parentSubtrees.size(); if (parentSubtreesSize == 1) { return Collections.emptySet(); } Collection<MultiTreeNode<T>> siblings = new HashSet<>(parentSubtreesSize - 1); for (TreeNode<T> parentSubtree : parentSubtrees) { if (!parentSubtree.equals(this)) { siblings.add((MultiTreeNode<T>) parentSubtree); } } return siblings; } MultiTreeNode(T data); }
MultiTreeNode extends TreeNode<T> { public Collection<? extends MultiTreeNode<T>> siblings() { if (isRoot()) { String message = String.format("Unable to find the siblings. The tree node %1$s is root", root()); throw new TreeNodeException(message); } Collection<? extends TreeNode<T>> parentSubtrees = parent.subtrees(); int parentSubtreesSize = parentSubtrees.size(); if (parentSubtreesSize == 1) { return Collections.emptySet(); } Collection<MultiTreeNode<T>> siblings = new HashSet<>(parentSubtreesSize - 1); for (TreeNode<T> parentSubtree : parentSubtrees) { if (!parentSubtree.equals(this)) { siblings.add((MultiTreeNode<T>) parentSubtree); } } return siblings; } 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); }
MultiTreeNode extends TreeNode<T> { public Collection<? extends MultiTreeNode<T>> siblings() { if (isRoot()) { String message = String.format("Unable to find the siblings. The tree node %1$s is root", root()); throw new TreeNodeException(message); } Collection<? extends TreeNode<T>> parentSubtrees = parent.subtrees(); int parentSubtreesSize = parentSubtrees.size(); if (parentSubtreesSize == 1) { return Collections.emptySet(); } Collection<MultiTreeNode<T>> siblings = new HashSet<>(parentSubtreesSize - 1); for (TreeNode<T> parentSubtree : parentSubtrees) { if (!parentSubtree.equals(this)) { siblings.add((MultiTreeNode<T>) parentSubtree); } } return siblings; } 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);  }