From 946cab444bc301d8a7c756a1bab039558288de89 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Wed, 11 Oct 2017 13:41:07 -0300 Subject: Cleanup work --- .../utils/funcdata/bst/BinarySearchTreeNode.java | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java') diff --git a/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java b/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java index 9f45c17..3124474 100644 --- a/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java +++ b/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java @@ -16,28 +16,26 @@ import java.util.function.Predicate; * @author ben * * @param - * The data type stored in the tree. + * The data type stored in the tree. */ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { - /* - * The left child of this node - */ + /* The left child of this node */ private ITreePart left; - /* - * The right child of this node - */ + /* The right child of this node */ private ITreePart right; /** * Create a new node with the specified data and children. * * @param element - * The data to store in this node. + * The data to store in this node. + * * @param lft - * The left child of this node. + * The left child of this node. + * * @param rght - * The right child of this node. + * The right child of this node. */ public BinarySearchTreeNode(final T element, final ITreePart lft, final ITreePart rght) { super(element); @@ -154,7 +152,6 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { case RIGHT: return right.directedWalk(treeWalker); case FAILURE: - return false; default: return false; } @@ -163,9 +160,11 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { @Override public boolean forEach(final TreeLinearizationMethod linearizationMethod, final Predicate traversalPredicate) { - if (linearizationMethod == null) + if (linearizationMethod == null) { throw new NullPointerException("Linearization method must not be null"); - else if (traversalPredicate == null) throw new NullPointerException("Predicate must not be null"); + } else if (traversalPredicate == null) { + throw new NullPointerException("Predicate must not be null"); + } switch (linearizationMethod) { case PREORDER: @@ -175,11 +174,13 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { case POSTORDER: return postorderTraverse(linearizationMethod, traversalPredicate); default: - throw new IllegalArgumentException( - "Passed an incorrect TreeLinearizationMethod " + linearizationMethod + ". WAT"); + String msg = String.format("Passed an incorrect TreeLinearizationMethod %s. WAT", linearizationMethod); + + throw new IllegalArgumentException(msg); } } + /* Do an in-order traversal. */ private boolean inorderTraverse(final TreeLinearizationMethod linearizationMethod, final Predicate traversalPredicate) { if (!traverseLeftBranch(linearizationMethod, traversalPredicate)) return false; @@ -191,6 +192,7 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { return true; } + /* Do a post-order traversal. */ private boolean postorderTraverse(final TreeLinearizationMethod linearizationMethod, final Predicate traversalPredicate) { if (!traverseLeftBranch(linearizationMethod, traversalPredicate)) return false; @@ -203,6 +205,7 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { } + /* Do a pre-order traversal. */ private boolean preorderTraverse(final TreeLinearizationMethod linearizationMethod, final Predicate traversalPredicate) { if (!traverseElement(traversalPredicate)) return false; @@ -214,6 +217,7 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { return true; } + /* Traverse an element. */ private boolean traverseElement(final Predicate traversalPredicate) { boolean nodeSuccesfullyTraversed; @@ -226,6 +230,7 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { return nodeSuccesfullyTraversed; } + /* Traverse the left branch of a tree. */ private boolean traverseLeftBranch(final TreeLinearizationMethod linearizationMethod, final Predicate traversalPredicate) { boolean leftSuccesfullyTraversed; @@ -239,6 +244,7 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { return leftSuccesfullyTraversed; } + /* Traverse the right branch of a tree. */ private boolean traverseRightBranch(final TreeLinearizationMethod linearizationMethod, final Predicate traversalPredicate) { boolean rightSuccesfullyTraversed; -- cgit v1.2.3