summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/funcdata/bst
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/bjc/funcdata/bst')
-rw-r--r--src/main/java/bjc/funcdata/bst/BinarySearchTree.java79
-rw-r--r--src/main/java/bjc/funcdata/bst/BinarySearchTreeLeaf.java43
-rw-r--r--src/main/java/bjc/funcdata/bst/BinarySearchTreeNode.java126
-rw-r--r--src/main/java/bjc/funcdata/bst/DirectedWalkFunction.java10
-rw-r--r--src/main/java/bjc/funcdata/bst/ITreePart.java47
-rw-r--r--src/main/java/bjc/funcdata/bst/TreeLinearizationMethod.java12
6 files changed, 182 insertions, 135 deletions
diff --git a/src/main/java/bjc/funcdata/bst/BinarySearchTree.java b/src/main/java/bjc/funcdata/bst/BinarySearchTree.java
index d0319e4..e22a8da 100644
--- a/src/main/java/bjc/funcdata/bst/BinarySearchTree.java
+++ b/src/main/java/bjc/funcdata/bst/BinarySearchTree.java
@@ -14,7 +14,7 @@ import bjc.funcdata.IList;
* @author ben
*
* @param <T>
- * The data type stored in the node.
+ * The data type stored in the node.
*/
public class BinarySearchTree<T> {
/* The comparator for use in ordering items */
@@ -30,10 +30,11 @@ public class BinarySearchTree<T> {
* Create a new tree using the specified way to compare elements.
*
* @param cmp
- * The thing to use for comparing elements
+ * The thing to use for comparing elements
*/
public BinarySearchTree(final Comparator<T> cmp) {
- if(cmp == null) throw new NullPointerException("Comparator must not be null");
+ if (cmp == null)
+ throw new NullPointerException("Comparator must not be null");
elementCount = 0;
comparator = cmp;
@@ -43,12 +44,12 @@ public class BinarySearchTree<T> {
* Add a node to the binary search tree.
*
* @param element
- * The data to add to the binary search tree.
+ * The data to add to the binary search tree.
*/
public void addNode(final T element) {
elementCount++;
- if(root == null) {
+ if (root == null) {
root = new BinarySearchTreeNode<>(element, null, null);
} else {
root.add(element, comparator);
@@ -59,18 +60,20 @@ public class BinarySearchTree<T> {
* Check if an adjusted pivot falls with the bounds of a list.
*
* @param elements
- * The list to get bounds from.
+ * The list to get bounds from.
*
* @param pivot
- * The pivot.
+ * The pivot.
*
* @param pivotAdjustment
- * The distance from the pivot.
+ * The distance from the pivot.
*
* @return Whether the adjusted pivot is with the list.
*/
- private boolean adjustedPivotInBounds(final IList<T> elements, final int pivot, final int pivotAdjustment) {
- return ((pivot - pivotAdjustment) >= 0) && ((pivot + pivotAdjustment) < elements.getSize());
+ private boolean adjustedPivotInBounds(final IList<T> elements, final int pivot,
+ final int pivotAdjustment) {
+ return ((pivot - pivotAdjustment) >= 0)
+ && ((pivot + pivotAdjustment) < elements.getSize());
}
/**
@@ -92,14 +95,13 @@ public class BinarySearchTree<T> {
int pivotAdjustment = 0;
/* Add elements until there aren't any left. */
- while(adjustedPivotInBounds(elements, pivot, pivotAdjustment)) {
- if(root == null) {
+ while (adjustedPivotInBounds(elements, pivot, pivotAdjustment)) {
+ if (root == null) {
/* Create a new root element. */
root = new BinarySearchTreeNode<>(elements.getByIndex(pivot), null, null);
} else {
/*
- * Add the left and right elements in a balanced
- * manner.
+ * Add the left and right elements in a balanced manner.
*/
root.add(elements.getByIndex(pivot + pivotAdjustment), comparator);
root.add(elements.getByIndex(pivot - pivotAdjustment), comparator);
@@ -110,9 +112,9 @@ public class BinarySearchTree<T> {
}
/* Add any trailing unbalanced elements. */
- if(pivot - pivotAdjustment >= 0) {
+ if (pivot - pivotAdjustment >= 0) {
root.add(elements.getByIndex(pivot - pivotAdjustment), comparator);
- } else if(pivot + pivotAdjustment < elements.getSize()) {
+ } else if (pivot + pivotAdjustment < elements.getSize()) {
root.add(elements.getByIndex(pivot + pivotAdjustment), comparator);
}
}
@@ -120,11 +122,11 @@ public class BinarySearchTree<T> {
/**
* Soft-delete a node from the tree.
*
- * Soft-deleted nodes stay in the tree until trim()/balance() is
- * invoked, and are not included in traversals/finds.
+ * Soft-deleted nodes stay in the tree until trim()/balance() is invoked, and
+ * are not included in traversals/finds.
*
* @param element
- * The node to delete
+ * The node to delete
*/
public void deleteNode(final T element) {
elementCount--;
@@ -145,7 +147,7 @@ public class BinarySearchTree<T> {
* Check if a node is in the tree.
*
* @param element
- * The node to check the presence of for the tree..
+ * The node to check the presence of for the tree..
*
* @return Whether or not the node is in the tree.
*/
@@ -157,15 +159,16 @@ public class BinarySearchTree<T> {
* Traverse the tree in a specified way until the function fails.
*
* @param linearizationMethod
- * The way to linearize the tree for traversal.
+ * The way to linearize the tree for traversal.
*
* @param traversalPredicate
- * The function to use until it fails.
+ * The function to use until it fails.
*/
- public void traverse(final TreeLinearizationMethod linearizationMethod, final Predicate<T> traversalPredicate) {
- if(linearizationMethod == null) {
+ public void traverse(final TreeLinearizationMethod linearizationMethod,
+ final Predicate<T> traversalPredicate) {
+ 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 nulls");
}
@@ -177,8 +180,7 @@ public class BinarySearchTree<T> {
final List<T> nodes = new ArrayList<>(elementCount);
/*
- * Add all non-soft deleted nodes to the tree in insertion
- * order.
+ * Add all non-soft deleted nodes to the tree in insertion order.
*/
traverse(TreeLinearizationMethod.PREORDER, node -> {
nodes.add(node);
@@ -194,7 +196,8 @@ public class BinarySearchTree<T> {
@Override
public String toString() {
- return String.format("BinarySearchTree [elementCount=%s, root='%s']", elementCount, root);
+ return String.format("BinarySearchTree [elementCount=%s, root='%s']",
+ elementCount, root);
}
@Override
@@ -208,16 +211,22 @@ public class BinarySearchTree<T> {
@Override
public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof BinarySearchTree<?>)) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof BinarySearchTree<?>))
+ return false;
final BinarySearchTree<?> other = (BinarySearchTree<?>) obj;
- if(elementCount != other.elementCount) return false;
- if(root == null) {
- if(other.root != null) return false;
- } else if(!root.equals(other.root)) return false;
+ if (elementCount != other.elementCount)
+ return false;
+ if (root == null) {
+ if (other.root != null)
+ return false;
+ } else if (!root.equals(other.root))
+ return false;
return true;
}
diff --git a/src/main/java/bjc/funcdata/bst/BinarySearchTreeLeaf.java b/src/main/java/bjc/funcdata/bst/BinarySearchTreeLeaf.java
index dfad3d9..0b99cad 100644
--- a/src/main/java/bjc/funcdata/bst/BinarySearchTreeLeaf.java
+++ b/src/main/java/bjc/funcdata/bst/BinarySearchTreeLeaf.java
@@ -11,7 +11,7 @@ import java.util.function.Predicate;
* @author ben
*
* @param <T>
- * The data stored in the tree.
+ * The data stored in the tree.
*/
public class BinarySearchTreeLeaf<T> implements ITreePart<T> {
/** The data held in this tree leaf */
@@ -24,7 +24,7 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> {
* Create a new leaf holding the specified data.
*
* @param element
- * The data for the leaf to hold.
+ * The data for the leaf to hold.
*/
public BinarySearchTreeLeaf(final T element) {
data = element;
@@ -36,8 +36,10 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> {
}
@Override
- public <E> E collapse(final Function<T, E> leafTransformer, final BiFunction<E, E, E> branchCollapser) {
- if(leafTransformer == null) throw new NullPointerException("Transformer must not be null");
+ public <E> E collapse(final Function<T, E> leafTransformer,
+ final BiFunction<E, E, E> branchCollapser) {
+ if (leafTransformer == null)
+ throw new NullPointerException("Transformer must not be null");
return leafTransformer.apply(data);
}
@@ -54,16 +56,17 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> {
@Override
public void delete(final T element, final Comparator<T> comparator) {
- if(data.equals(element)) {
+ if (data.equals(element)) {
isDeleted = true;
}
}
@Override
public boolean directedWalk(final DirectedWalkFunction<T> treeWalker) {
- if(treeWalker == null) throw new NullPointerException("Tree walker must not be null");
+ if (treeWalker == null)
+ throw new NullPointerException("Tree walker must not be null");
- switch(treeWalker.walk(data)) {
+ switch (treeWalker.walk(data)) {
case SUCCESS:
return true;
/* We don't have any children to care about. */
@@ -78,14 +81,16 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> {
@Override
public boolean forEach(final TreeLinearizationMethod linearizationMethod,
final Predicate<T> traversalPredicate) {
- if(traversalPredicate == null) throw new NullPointerException("Predicate must not be null");
+ if (traversalPredicate == null)
+ throw new NullPointerException("Predicate must not be null");
return traversalPredicate.test(data);
}
@Override
public String toString() {
- return String.format("BinarySearchTreeLeaf [data='%s', isDeleted=%s]", data, isDeleted);
+ return String.format("BinarySearchTreeLeaf [data='%s', isDeleted=%s]", data,
+ isDeleted);
}
@Override
@@ -99,16 +104,22 @@ public class BinarySearchTreeLeaf<T> implements ITreePart<T> {
@Override
public boolean equals(final Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof BinarySearchTreeLeaf<?>)) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof BinarySearchTreeLeaf<?>))
+ return false;
final BinarySearchTreeLeaf<?> other = (BinarySearchTreeLeaf<?>) obj;
- if(data == null) {
- if(other.data != null) return false;
- } else if(!data.equals(other.data)) return false;
- if(isDeleted != other.isDeleted) return false;
+ if (data == null) {
+ if (other.data != null)
+ return false;
+ } else if (!data.equals(other.data))
+ return false;
+ if (isDeleted != other.isDeleted)
+ return false;
return true;
}
diff --git a/src/main/java/bjc/funcdata/bst/BinarySearchTreeNode.java b/src/main/java/bjc/funcdata/bst/BinarySearchTreeNode.java
index 0453f80..a73f81a 100644
--- a/src/main/java/bjc/funcdata/bst/BinarySearchTreeNode.java
+++ b/src/main/java/bjc/funcdata/bst/BinarySearchTreeNode.java
@@ -16,7 +16,7 @@ import java.util.function.Predicate;
* @author ben
*
* @param <T>
- * The data type stored in the tree.
+ * The data type stored in the tree.
*/
public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
/* The left child of this node */
@@ -29,15 +29,16 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
* 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<T> lft, final ITreePart<T> rght) {
+ public BinarySearchTreeNode(final T element, final ITreePart<T> lft,
+ final ITreePart<T> rght) {
super(element);
this.left = lft;
this.right = rght;
@@ -45,24 +46,25 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@Override
public void add(final T element, final Comparator<T> 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");
break;
case 1:
- if(right == null) {
+ if (right == null) {
right = new BinarySearchTreeNode<>(element, null, null);
} else {
right.add(element, comparator);
@@ -74,17 +76,19 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
}
@Override
- public <E> E collapse(final Function<T, E> nodeCollapser, final BiFunction<E, E, E> branchCollapser) {
- if(nodeCollapser == null || branchCollapser == null)
+ public <E> E collapse(final Function<T, E> nodeCollapser,
+ final BiFunction<E, E, E> branchCollapser) {
+ 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) {
- final E collapsedRightBranch = right.collapse(nodeCollapser, branchCollapser);
+ if (right != null) {
+ final E collapsedRightBranch
+ = right.collapse(nodeCollapser, branchCollapser);
final E collapsedBranches = branchCollapser.apply(collapsedLeftBranch,
collapsedRightBranch);
@@ -95,7 +99,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
return branchCollapser.apply(collapsedNode, collapsedLeftBranch);
}
- if(right != null) {
+ if (right != null) {
final E collapsedRightBranch = right.collapse(nodeCollapser, branchCollapser);
return branchCollapser.apply(collapsedNode, collapsedRightBranch);
@@ -106,10 +110,11 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@Override
public boolean contains(final T element, final Comparator<T> 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:
@@ -124,10 +129,11 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@Override
public void delete(final T element, final Comparator<T> 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:
@@ -143,9 +149,10 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@Override
public boolean directedWalk(final DirectedWalkFunction<T> 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:
@@ -161,13 +168,13 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@Override
public boolean forEach(final TreeLinearizationMethod linearizationMethod,
final Predicate<T> 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:
@@ -175,8 +182,9 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
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);
}
@@ -185,11 +193,14 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
/* Do an in-order traversal. */
private boolean inorderTraverse(final TreeLinearizationMethod linearizationMethod,
final Predicate<T> 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;
}
@@ -197,11 +208,14 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
/* Do a post-order traversal. */
private boolean postorderTraverse(final TreeLinearizationMethod linearizationMethod,
final Predicate<T> 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;
@@ -210,11 +224,14 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
/* Do a pre-order traversal. */
private boolean preorderTraverse(final TreeLinearizationMethod linearizationMethod,
final Predicate<T> 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;
}
@@ -223,7 +240,7 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
private boolean traverseElement(final Predicate<T> traversalPredicate) {
boolean nodeSuccesfullyTraversed;
- if(isDeleted) {
+ if (isDeleted) {
nodeSuccesfullyTraversed = true;
} else {
nodeSuccesfullyTraversed = traversalPredicate.test(data);
@@ -237,10 +254,11 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
final Predicate<T> traversalPredicate) {
boolean leftSuccesfullyTraversed;
- if(left == null) {
+ if (left == null) {
leftSuccesfullyTraversed = true;
} else {
- leftSuccesfullyTraversed = left.forEach(linearizationMethod, traversalPredicate);
+ leftSuccesfullyTraversed
+ = left.forEach(linearizationMethod, traversalPredicate);
}
return leftSuccesfullyTraversed;
@@ -251,10 +269,11 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
final Predicate<T> traversalPredicate) {
boolean rightSuccesfullyTraversed;
- if(right == null) {
+ if (right == null) {
rightSuccesfullyTraversed = true;
} else {
- rightSuccesfullyTraversed = right.forEach(linearizationMethod, traversalPredicate);
+ rightSuccesfullyTraversed
+ = right.forEach(linearizationMethod, traversalPredicate);
}
return rightSuccesfullyTraversed;
@@ -276,19 +295,26 @@ public class BinarySearchTreeNode<T> extends BinarySearchTreeLeaf<T> {
@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;
}
diff --git a/src/main/java/bjc/funcdata/bst/DirectedWalkFunction.java b/src/main/java/bjc/funcdata/bst/DirectedWalkFunction.java
index ac2b918..4f64339 100644
--- a/src/main/java/bjc/funcdata/bst/DirectedWalkFunction.java
+++ b/src/main/java/bjc/funcdata/bst/DirectedWalkFunction.java
@@ -6,7 +6,7 @@ package bjc.funcdata.bst;
* @author ben
*
* @param <T>
- * The type of element stored in the walked tree
+ * The type of element stored in the walked tree
*/
@FunctionalInterface
public interface DirectedWalkFunction<T> {
@@ -19,13 +19,11 @@ public interface DirectedWalkFunction<T> {
/** Specifies that the function has failed. */
FAILURE,
/**
- * Specifies that the function wants to move left in the tree
- * next.
+ * Specifies that the function wants to move left in the tree next.
*/
LEFT,
/**
- * Specifies that the function wants to move right in the tree
- * next.
+ * Specifies that the function wants to move right in the tree next.
*/
RIGHT,
/** Specifies that the function has succesfully completed */
@@ -36,7 +34,7 @@ public interface DirectedWalkFunction<T> {
* Perform a directed walk on a node of a tree.
*
* @param element
- * The data stored in the node currently being visited.
+ * The data stored in the node currently being visited.
*
* @return The way the function wants the walk to go next.
*/
diff --git a/src/main/java/bjc/funcdata/bst/ITreePart.java b/src/main/java/bjc/funcdata/bst/ITreePart.java
index 903965f..bac640d 100644
--- a/src/main/java/bjc/funcdata/bst/ITreePart.java
+++ b/src/main/java/bjc/funcdata/bst/ITreePart.java
@@ -11,18 +11,18 @@ import java.util.function.Predicate;
* @author ben
*
* @param <T>
- * The data contained in this part of the tree.
+ * The data contained in this part of the tree.
*/
public interface ITreePart<T> {
/**
* Add a element below this tree part somewhere.
*
* @param element
- * The element to add below this tree part
+ * The element to add below this tree part
*
* @param comparator
- * The thing to use for comparing values to find where to insert
- * the tree part.
+ * The thing to use for comparing values to find where to
+ * insert the tree part.
*/
public void add(T element, Comparator<T> comparator);
@@ -32,30 +32,32 @@ public interface ITreePart<T> {
* Does not change the underlying tree.
*
* @param <E>
- * The type of the final collapsed value
+ * The type of the final collapsed value
*
* @param nodeCollapser
- * The function to use to transform data into mapped form.
+ * The function to use to transform data into mapped
+ * form.
*
* @param branchCollapser
- * The function to use to collapse data in mapped form into a
- * single value.
+ * The function to use to collapse data in mapped form
+ * into a single value.
*
* @return A single value from collapsing the tree.
*/
- public <E> E collapse(Function<T, E> nodeCollapser, BiFunction<E, E, E> branchCollapser);
+ public <E> E collapse(Function<T, E> nodeCollapser,
+ BiFunction<E, E, E> branchCollapser);
/**
* Check if this tre part or below it contains the specified data item.
*
* @param element
- * The data item to look for.
+ * The data item to look for.
*
* @param comparator
- * The comparator to use to search for the data item.
+ * The comparator to use to search for the data item.
*
- * @return Whether or not the given item is contained in this tree part
- * or its children.
+ * @return Whether or not the given item is contained in this tree part or its
+ * children.
*/
public boolean contains(T element, Comparator<T> comparator);
@@ -70,10 +72,10 @@ public interface ITreePart<T> {
* Remove the given node from this tree part and any of its children.
*
* @param element
- * The data item to remove.
+ * The data item to remove.
*
* @param comparator
- * The comparator to use to search for the data item.
+ * The comparator to use to search for the data item.
*/
public void delete(T element, Comparator<T> comparator);
@@ -81,24 +83,25 @@ public interface ITreePart<T> {
* Execute a directed walk through the tree.
*
* @param walker
- * The function to use to direct the walk through the tree.
+ * The function to use to direct the walk through the tree.
*
* @return Whether the directed walk finished successfully.
*/
public boolean directedWalk(DirectedWalkFunction<T> walker);
/**
- * Execute a provided function for each element of tree it succesfully
- * completes for.
+ * Execute a provided function for each element of tree it succesfully completes
+ * for.
*
* @param linearizationMethod
- * The way to linearize the tree for executing.
+ * The way to linearize the tree for executing.
*
* @param predicate
- * The predicate to apply to each element, where it returning
- * false terminates traversal early.
+ * The predicate to apply to each element, where it
+ * returning false terminates traversal early.
*
* @return Whether the traversal finished succesfully.
*/
- public boolean forEach(TreeLinearizationMethod linearizationMethod, Predicate<T> predicate);
+ public boolean forEach(TreeLinearizationMethod linearizationMethod,
+ Predicate<T> predicate);
}
diff --git a/src/main/java/bjc/funcdata/bst/TreeLinearizationMethod.java b/src/main/java/bjc/funcdata/bst/TreeLinearizationMethod.java
index 35b116b..65c013b 100644
--- a/src/main/java/bjc/funcdata/bst/TreeLinearizationMethod.java
+++ b/src/main/java/bjc/funcdata/bst/TreeLinearizationMethod.java
@@ -7,18 +7,18 @@ package bjc.funcdata.bst;
*/
public enum TreeLinearizationMethod {
/**
- * Visit the left side of this tree part, the tree part itself, and then
- * the right part.
+ * Visit the left side of this tree part, the tree part itself, and then the
+ * right part.
*/
INORDER,
/**
- * Visit the left side of this tree part, the right side, and then the
- * tree part itself.
+ * Visit the left side of this tree part, the right side, and then the tree part
+ * itself.
*/
POSTORDER,
/**
- * Visit the tree part itself, then the left side of tthis tree part and
- * then the right part.
+ * Visit the tree part itself, then the left side of tthis tree part and then
+ * the right part.
*/
PREORDER
}