From df94066e3af02ff02d5ab4d033a3d603f743234c Mon Sep 17 00:00:00 2001 From: bjculkin Date: Mon, 12 Feb 2018 22:45:04 -0500 Subject: Formatting pass --- .../utils/funcdata/bst/BinarySearchTreeNode.java | 92 +++++++++++----------- 1 file changed, 47 insertions(+), 45 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 3124474..eb7b6b5 100644 --- a/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java +++ b/base/src/main/java/bjc/utils/funcdata/bst/BinarySearchTreeNode.java @@ -16,7 +16,7 @@ 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 */ @@ -29,13 +29,13 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { * 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); @@ -45,23 +45,24 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { @Override public void add(final T element, final Comparator comparator) { - if (comparator == null) throw new NullPointerException("Comparator must not be null"); + if(comparator == null) throw new NullPointerException("Comparator must not be null"); - switch (comparator.compare(data, element)) { + switch(comparator.compare(data, element)) { case -1: - if (left == null) { + if(left == null) { left = new BinarySearchTreeNode<>(element, null, null); } else { left.add(element, comparator); } break; case 0: - if (isDeleted) { + if(isDeleted) { isDeleted = false; - } else throw new IllegalArgumentException("Can't add duplicate values"); + } else + throw new IllegalArgumentException("Can't add duplicate values"); break; case 1: - if (right == null) { + if(right == null) { right = new BinarySearchTreeNode<>(element, null, null); } else { right.add(element, comparator); @@ -74,15 +75,15 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { @Override public E collapse(final Function nodeCollapser, final BiFunction branchCollapser) { - if (nodeCollapser == null || branchCollapser == null) + if(nodeCollapser == null || branchCollapser == null) throw new NullPointerException("Collapser must not be null"); final E collapsedNode = nodeCollapser.apply(data); - if (left != null) { + if(left != null) { final E collapsedLeftBranch = left.collapse(nodeCollapser, branchCollapser); - if (right != null) { + if(right != null) { final E collapsedRightBranch = right.collapse(nodeCollapser, branchCollapser); final E collapsedBranches = branchCollapser.apply(collapsedLeftBranch, @@ -94,7 +95,7 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { return branchCollapser.apply(collapsedNode, collapsedLeftBranch); } - if (right != null) { + if(right != null) { final E collapsedRightBranch = right.collapse(nodeCollapser, branchCollapser); return branchCollapser.apply(collapsedNode, collapsedRightBranch); @@ -105,10 +106,10 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { @Override public boolean contains(final T element, final Comparator comparator) { - if (comparator == null) throw new NullPointerException("Comparator must not be null"); + if(comparator == null) throw new NullPointerException("Comparator must not be null"); return directedWalk(currentElement -> { - switch (comparator.compare(element, currentElement)) { + switch(comparator.compare(element, currentElement)) { case -1: return LEFT; case 0: @@ -123,10 +124,10 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { @Override public void delete(final T element, final Comparator comparator) { - if (comparator == null) throw new NullPointerException("Comparator must not be null"); + if(comparator == null) throw new NullPointerException("Comparator must not be null"); directedWalk(currentElement -> { - switch (comparator.compare(data, element)) { + switch(comparator.compare(data, element)) { case -1: return left == null ? FAILURE : LEFT; case 0: @@ -142,9 +143,9 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { @Override public boolean directedWalk(final DirectedWalkFunction treeWalker) { - if (treeWalker == null) throw new NullPointerException("Walker must not be null"); + if(treeWalker == null) throw new NullPointerException("Walker must not be null"); - switch (treeWalker.walk(data)) { + switch(treeWalker.walk(data)) { case SUCCESS: return true; case LEFT: @@ -160,13 +161,13 @@ 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) { + } else if(traversalPredicate == null) { throw new NullPointerException("Predicate must not be null"); } - switch (linearizationMethod) { + switch(linearizationMethod) { case PREORDER: return preorderTraverse(linearizationMethod, traversalPredicate); case INORDER: @@ -174,7 +175,8 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { case POSTORDER: return postorderTraverse(linearizationMethod, traversalPredicate); default: - String msg = String.format("Passed an incorrect TreeLinearizationMethod %s. WAT", linearizationMethod); + String msg = String.format("Passed an incorrect TreeLinearizationMethod %s. WAT", + linearizationMethod); throw new IllegalArgumentException(msg); } @@ -183,11 +185,11 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { /* Do an in-order traversal. */ private boolean inorderTraverse(final TreeLinearizationMethod linearizationMethod, final Predicate traversalPredicate) { - if (!traverseLeftBranch(linearizationMethod, traversalPredicate)) return false; + if(!traverseLeftBranch(linearizationMethod, traversalPredicate)) return false; - if (!traverseElement(traversalPredicate)) return false; + if(!traverseElement(traversalPredicate)) return false; - if (!traverseRightBranch(linearizationMethod, traversalPredicate)) return false; + if(!traverseRightBranch(linearizationMethod, traversalPredicate)) return false; return true; } @@ -195,11 +197,11 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { /* Do a post-order traversal. */ private boolean postorderTraverse(final TreeLinearizationMethod linearizationMethod, final Predicate traversalPredicate) { - if (!traverseLeftBranch(linearizationMethod, traversalPredicate)) return false; + if(!traverseLeftBranch(linearizationMethod, traversalPredicate)) return false; - if (!traverseRightBranch(linearizationMethod, traversalPredicate)) return false; + if(!traverseRightBranch(linearizationMethod, traversalPredicate)) return false; - if (!traverseElement(traversalPredicate)) return false; + if(!traverseElement(traversalPredicate)) return false; return true; @@ -208,11 +210,11 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { /* Do a pre-order traversal. */ private boolean preorderTraverse(final TreeLinearizationMethod linearizationMethod, final Predicate traversalPredicate) { - if (!traverseElement(traversalPredicate)) return false; + if(!traverseElement(traversalPredicate)) return false; - if (!traverseLeftBranch(linearizationMethod, traversalPredicate)) return false; + if(!traverseLeftBranch(linearizationMethod, traversalPredicate)) return false; - if (!traverseRightBranch(linearizationMethod, traversalPredicate)) return false; + if(!traverseRightBranch(linearizationMethod, traversalPredicate)) return false; return true; } @@ -221,7 +223,7 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { private boolean traverseElement(final Predicate traversalPredicate) { boolean nodeSuccesfullyTraversed; - if (isDeleted) { + if(isDeleted) { nodeSuccesfullyTraversed = true; } else { nodeSuccesfullyTraversed = traversalPredicate.test(data); @@ -235,7 +237,7 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { final Predicate traversalPredicate) { boolean leftSuccesfullyTraversed; - if (left == null) { + if(left == null) { leftSuccesfullyTraversed = true; } else { leftSuccesfullyTraversed = left.forEach(linearizationMethod, traversalPredicate); @@ -249,7 +251,7 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { final Predicate traversalPredicate) { boolean rightSuccesfullyTraversed; - if (right == null) { + if(right == null) { rightSuccesfullyTraversed = true; } else { rightSuccesfullyTraversed = right.forEach(linearizationMethod, traversalPredicate); @@ -274,19 +276,19 @@ public class BinarySearchTreeNode extends BinarySearchTreeLeaf { @Override public boolean equals(final Object obj) { - if (this == obj) return true; - if (!super.equals(obj)) return false; - if (!(obj instanceof BinarySearchTreeNode)) return false; + if(this == obj) return true; + if(!super.equals(obj)) return false; + if(!(obj instanceof BinarySearchTreeNode)) return false; final BinarySearchTreeNode other = (BinarySearchTreeNode) obj; - if (left == null) { - if (other.left != null) return false; - } else if (!left.equals(other.left)) return false; + if(left == null) { + if(other.left != null) return false; + } else if(!left.equals(other.left)) return false; - if (right == null) { - if (other.right != null) return false; - } else if (!right.equals(other.right)) return false; + if(right == null) { + if(other.right != null) return false; + } else if(!right.equals(other.right)) return false; return true; } -- cgit v1.2.3