summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/data/ITree.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2018-02-12 22:45:04 -0500
committerbjculkin <bjculkin@mix.wvu.edu>2018-02-12 22:45:04 -0500
commitdf94066e3af02ff02d5ab4d033a3d603f743234c (patch)
tree168a1edaf58d386c175ffb601e9d4da8e13d31e2 /base/src/main/java/bjc/utils/data/ITree.java
parentae51c587c53f7ca311e556e3cbd0c5566d6c2843 (diff)
Formatting pass
Diffstat (limited to 'base/src/main/java/bjc/utils/data/ITree.java')
-rw-r--r--base/src/main/java/bjc/utils/data/ITree.java101
1 files changed, 45 insertions, 56 deletions
diff --git a/base/src/main/java/bjc/utils/data/ITree.java b/base/src/main/java/bjc/utils/data/ITree.java
index 450905b..5a4d645 100644
--- a/base/src/main/java/bjc/utils/data/ITree.java
+++ b/base/src/main/java/bjc/utils/data/ITree.java
@@ -14,7 +14,7 @@ import bjc.utils.functypes.ListFlattener;
* @author ben
*
* @param <ContainedType>
- * The type of data contained in the tree nodes.
+ * The type of data contained in the tree nodes.
*
*/
public interface ITree<ContainedType> {
@@ -22,7 +22,7 @@ public interface ITree<ContainedType> {
* Append a child to this node.
*
* @param child
- * The child to append to this node.
+ * The child to append to this node.
*/
void addChild(ITree<ContainedType> child);
@@ -30,7 +30,7 @@ public interface ITree<ContainedType> {
* Prepend a child to this node.
*
* @param child
- * The child to prepend to this node.
+ * The child to prepend to this node.
*/
void prependChild(ITree<ContainedType> child);
@@ -38,24 +38,23 @@ public interface ITree<ContainedType> {
* Collapse a tree into a single version.
*
* @param <NewType>
- * The intermediate type being folded.
+ * The intermediate type being folded.
*
* @param <ReturnedType>
- * The type that is the end result.
+ * The type that is the end result.
*
* @param leafTransform
- * The function to use to convert leaf values.
+ * The function to use to convert leaf values.
*
* @param nodeCollapser
- * The function to use to convert internal nodes and
- * their children.
+ * The function to use to convert internal nodes and their
+ * children.
*
* @param resultTransformer
- * The function to use to convert a state to the returned
- * version.
+ * The function to use to convert a state to the returned
+ * version.
*
- * @return
- * The final transformed state.
+ * @return The final transformed state.
*/
<NewType, ReturnedType> ReturnedType collapse(Function<ContainedType, NewType> leafTransform,
Function<ContainedType, ListFlattener<NewType>> nodeCollapser,
@@ -65,7 +64,7 @@ public interface ITree<ContainedType> {
* Execute a given action for each of this tree's children.
*
* @param action
- * The action to execute for each child.
+ * The action to execute for each child.
*/
void doForChildren(Consumer<ITree<ContainedType>> action);
@@ -74,14 +73,13 @@ public interface ITree<ContainedType> {
* those trees into a single tree.
*
* @param mapper
- * The function to use to map values into trees.
+ * The function to use to map values into trees.
*
- * @return
- * A tree, with some nodes expanded into trees.
+ * @return A tree, with some nodes expanded into trees.
*/
default ITree<ContainedType> flatMapTree(final Function<ContainedType, ITree<ContainedType>> mapper) {
return topDownTransform(dat -> TopDownTransformResult.PUSHDOWN, node -> {
- if (node.getChildrenCount() > 0) {
+ if(node.getChildrenCount() > 0) {
final ITree<ContainedType> parent = node.transformHead(mapper);
node.doForChildren(parent::addChild);
@@ -97,10 +95,9 @@ public interface ITree<ContainedType> {
* Get the specified child of this tree.
*
* @param childNo
- * The number of the child to get.
+ * The number of the child to get.
*
- * @return
- * The specified child of this tree.
+ * @return The specified child of this tree.
*/
default ITree<ContainedType> getChild(final int childNo) {
return transformChild(childNo, child -> child);
@@ -109,16 +106,14 @@ public interface ITree<ContainedType> {
/**
* Get a count of the number of direct children this node has.
*
- * @return
- * The number of direct children this node has.
+ * @return The number of direct children this node has.
*/
int getChildrenCount();
/**
* Get the data stored in this node.
*
- * @return
- * The data stored in this node.
+ * @return The data stored in this node.
*/
default ContainedType getHead() {
return transformHead(head -> head);
@@ -128,16 +123,15 @@ public interface ITree<ContainedType> {
* Rebuild the tree with the same structure, but different nodes.
*
* @param <MappedType>
- * The type of the new tree.
+ * The type of the new tree.
*
* @param leafTransformer
- * The function to use to transform leaf tokens.
+ * The function to use to transform leaf tokens.
*
* @param internalTransformer
- * The function to use to transform internal tokens.
+ * The function to use to transform internal tokens.
*
- * @return
- * The tree, with the nodes changed.
+ * @return The tree, with the nodes changed.
*/
<MappedType> ITree<MappedType> rebuildTree(Function<ContainedType, MappedType> leafTransformer,
Function<ContainedType, MappedType> internalTransformer);
@@ -146,10 +140,10 @@ public interface ITree<ContainedType> {
* Transform some of the nodes in this tree.
*
* @param nodePicker
- * The predicate to use to pick nodes to transform.
+ * The predicate to use to pick nodes to transform.
*
* @param transformer
- * The function to use to transform picked nodes.
+ * The function to use to transform picked nodes.
*/
void selectiveTransform(Predicate<ContainedType> nodePicker, UnaryOperator<ContainedType> transformer);
@@ -157,13 +151,12 @@ public interface ITree<ContainedType> {
* Do a top-down transform of the tree.
*
* @param transformPicker
- * The function to use to pick how to progress.
+ * The function to use to pick how to progress.
*
* @param transformer
- * The function used to transform picked subtrees.
+ * The function used to transform picked subtrees.
*
- * @return
- * The tree with the transform applied to picked subtrees.
+ * @return The tree with the transform applied to picked subtrees.
*/
ITree<ContainedType> topDownTransform(Function<ContainedType, TopDownTransformResult> transformPicker,
UnaryOperator<ITree<ContainedType>> transformer);
@@ -172,20 +165,19 @@ public interface ITree<ContainedType> {
* Transform one of this nodes children.
*
* @param <TransformedType>
- * The type of the transformed value.
+ * The type of the transformed value.
*
* @param childNo
- * The number of the child to transform.
+ * The number of the child to transform.
*
* @param transformer
- * The function to use to transform the value.
+ * The function to use to transform the value.
*
- * @return
- * The transformed value.
+ * @return The transformed value.
*
* @throws IllegalArgumentException
- * if the childNo is out of bounds (0 &lt;= childNo &lt;=
- * childCount()).
+ * if the childNo is out of bounds (0 &lt;= childNo &lt;=
+ * childCount()).
*/
<TransformedType> TransformedType transformChild(int childNo,
Function<ITree<ContainedType>, TransformedType> transformer);
@@ -194,13 +186,12 @@ public interface ITree<ContainedType> {
* Transform the value that is the head of this node.
*
* @param <TransformedType>
- * The type of the transformed value.
+ * The type of the transformed value.
*
* @param transformer
- * The function to use to transform the value.
+ * The function to use to transform the value.
*
- * @return
- * The transformed value.
+ * @return The transformed value.
*/
<TransformedType> TransformedType transformHead(Function<ContainedType, TransformedType> transformer);
@@ -208,13 +199,12 @@ public interface ITree<ContainedType> {
* Transform the tree into a tree with a different type of token.
*
* @param <MappedType>
- * The type of the new tree.
+ * The type of the new tree.
*
* @param transformer
- * The function to use to transform tokens.
+ * The function to use to transform tokens.
*
- * @return
- * A tree with the token types transformed.
+ * @return A tree with the token types transformed.
*/
default <MappedType> ITree<MappedType> transformTree(final Function<ContainedType, MappedType> transformer) {
return rebuildTree(transformer, transformer);
@@ -224,10 +214,10 @@ public interface ITree<ContainedType> {
* Perform an action on each part of the tree.
*
* @param linearizationMethod
- * The way to traverse the tree.
+ * The way to traverse the tree.
*
* @param action
- * The action to perform on each tree node.
+ * The action to perform on each tree node.
*/
void traverse(TreeLinearizationMethod linearizationMethod, Consumer<ContainedType> action);
@@ -235,11 +225,10 @@ public interface ITree<ContainedType> {
* Find the farthest to right child that satisfies the given predicate.
*
* @param childPred
- * The predicate to satisfy.
+ * The predicate to satisfy.
*
- * @return
- * The index of the right-most child that satisfies the predicate,
- * or -1 if one doesn't exist.
+ * @return The index of the right-most child that satisfies the
+ * predicate, or -1 if one doesn't exist.
*/
int revFind(Predicate<ITree<ContainedType>> childPred);
}