summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java148
1 files changed, 78 insertions, 70 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java
index bbcefd3..866471c 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java
@@ -25,43 +25,6 @@ public interface ITree<ContainedType> {
public void addChild(ITree<ContainedType> child);
/**
- * Transform the value that is the head of this node
- *
- * @param <TransformedType>
- * The type of the transformed value
- * @param transformer
- * The function to use to transform the value
- * @return The transformed value
- */
- public <TransformedType> TransformedType transformHead(
- Function<ContainedType, TransformedType> transformer);
-
- /**
- * Get a count of the number of direct children this node has
- *
- * @return The number of direct children this node has
- */
- public int getChildrenCount();
-
- /**
- * Transform one of this nodes children
- *
- * @param <TransformedType>
- * The type of the transformed value
- * @param childNo
- * The number of the child to transform
- * @param transformer
- * The function to use to transform the value
- * @return The transformed value
- *
- * @throws IllegalArgumentException
- * if the childNo is out of bounds (0 <= childNo <=
- * childCount())
- */
- public <TransformedType> TransformedType transformChild(int childNo,
- Function<ITree<ContainedType>, TransformedType> transformer);
-
- /**
* Collapse a tree into a single version
*
* @param <NewType>
@@ -84,6 +47,14 @@ public interface ITree<ContainedType> {
Function<NewType, ReturnedType> resultTransformer);
/**
+ * Execute a given action for each of this tree's children
+ *
+ * @param action
+ * The action to execute for each child
+ */
+ void doForChildren(Consumer<ITree<ContainedType>> action);
+
+ /**
* Expand the nodes of a tree into trees, and then merge the contents
* of those trees into a single tree
*
@@ -95,38 +66,31 @@ public interface ITree<ContainedType> {
Function<ContainedType, ITree<ContainedType>> mapper);
/**
- * Transform some of the nodes in this tree
+ * Get the specified child of this tree
*
- * @param nodePicker
- * The predicate to use to pick nodes to transform
- * @param transformer
- * The function to use to transform picked nodes
+ * @param childNo
+ * The number of the child to get
+ * @return The specified child of this tree
*/
- public void selectiveTransform(Predicate<ContainedType> nodePicker,
- UnaryOperator<ContainedType> transformer);
+ default ITree<ContainedType> getChild(int childNo) {
+ return transformChild(childNo, (child) -> child);
+ }
/**
- * Transform the tree into a tree with a different type of token
+ * Get a count of the number of direct children this node has
*
- * @param <MappedType>
- * The type of the new tree
- * @param transformer
- * The function to use to transform tokens
- * @return A tree with the token types transformed
+ * @return The number of direct children this node has
*/
- public <MappedType> ITree<MappedType>
- transformTree(Function<ContainedType, MappedType> transformer);
+ public int getChildrenCount();
/**
- * Perform an action on each part of the tree
+ * Get the data stored in this node
*
- * @param linearizationMethod
- * The way to traverse the tree
- * @param action
- * The action to perform on each tree node
+ * @return The data stored in this node
*/
- public void traverse(TreeLinearizationMethod linearizationMethod,
- Consumer<ContainedType> action);
+ default ContainedType getHead() {
+ return transformHead((head) -> head);
+ }
/**
* Rebuild the tree with the same structure, but different nodes
@@ -144,6 +108,17 @@ public interface ITree<ContainedType> {
Function<ContainedType, MappedType> operatorTransformer);
/**
+ * Transform some of the nodes in this tree
+ *
+ * @param nodePicker
+ * The predicate to use to pick nodes to transform
+ * @param transformer
+ * The function to use to transform picked nodes
+ */
+ public void selectiveTransform(Predicate<ContainedType> nodePicker,
+ UnaryOperator<ContainedType> transformer);
+
+ /**
* Do a top-down transform of the tree
*
* @param transformPicker
@@ -157,22 +132,55 @@ public interface ITree<ContainedType> {
UnaryOperator<ITree<ContainedType>> transformer);
/**
- * Get the specified child of this tree
+ * Transform one of this nodes children
*
+ * @param <TransformedType>
+ * The type of the transformed value
* @param childNo
- * The number of the child to get
- * @return The specified child of this tree
+ * The number of the child to transform
+ * @param transformer
+ * The function to use to transform the value
+ * @return The transformed value
+ *
+ * @throws IllegalArgumentException
+ * if the childNo is out of bounds (0 <= childNo <=
+ * childCount())
*/
- default ITree<ContainedType> getChild(int childNo) {
- return transformChild(childNo, (child) -> child);
- }
+ public <TransformedType> TransformedType transformChild(int childNo,
+ Function<ITree<ContainedType>, TransformedType> transformer);
/**
- * Get the data stored in this node
+ * Transform the value that is the head of this node
*
- * @return The data stored in this node
+ * @param <TransformedType>
+ * The type of the transformed value
+ * @param transformer
+ * The function to use to transform the value
+ * @return The transformed value
*/
- default ContainedType getHead() {
- return transformHead((head) -> head);
- }
+ public <TransformedType> TransformedType transformHead(
+ Function<ContainedType, TransformedType> transformer);
+
+ /**
+ * Transform the tree into a tree with a different type of token
+ *
+ * @param <MappedType>
+ * The type of the new tree
+ * @param transformer
+ * The function to use to transform tokens
+ * @return A tree with the token types transformed
+ */
+ public <MappedType> ITree<MappedType>
+ transformTree(Function<ContainedType, MappedType> transformer);
+
+ /**
+ * Perform an action on each part of the tree
+ *
+ * @param linearizationMethod
+ * The way to traverse the tree
+ * @param action
+ * The action to perform on each tree node
+ */
+ public void traverse(TreeLinearizationMethod linearizationMethod,
+ Consumer<ContainedType> action);
}