From b4f5f98c0aa7fc892e96771ff2df729e61c21f74 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 18 Apr 2016 19:56:32 -0400 Subject: Minor code changes --- .../src/main/java/bjc/utils/funcdata/ITree.java | 148 +++++++++++---------- 1 file changed, 78 insertions(+), 70 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java') 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 @@ -24,43 +24,6 @@ public interface ITree { */ public void addChild(ITree child); - /** - * Transform the value that is the head of this node - * - * @param - * The type of the transformed value - * @param transformer - * The function to use to transform the value - * @return The transformed value - */ - public TransformedType transformHead( - Function 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 - * 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 transformChild(int childNo, - Function, TransformedType> transformer); - /** * Collapse a tree into a single version * @@ -83,6 +46,14 @@ public interface ITree { Function, NewType>> nodeCollapser, Function resultTransformer); + /** + * Execute a given action for each of this tree's children + * + * @param action + * The action to execute for each child + */ + void doForChildren(Consumer> 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 { Function> 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 nodePicker, - UnaryOperator transformer); + default ITree 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 - * 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 ITree - transformTree(Function 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 action); + default ContainedType getHead() { + return transformHead((head) -> head); + } /** * Rebuild the tree with the same structure, but different nodes @@ -143,6 +107,17 @@ public interface ITree { Function leafTransformer, Function 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 nodePicker, + UnaryOperator transformer); + /** * Do a top-down transform of the tree * @@ -157,22 +132,55 @@ public interface ITree { UnaryOperator> transformer); /** - * Get the specified child of this tree + * Transform one of this nodes children * + * @param + * 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 getChild(int childNo) { - return transformChild(childNo, (child) -> child); - } + public TransformedType transformChild(int childNo, + Function, 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 + * 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 transformHead( + Function transformer); + + /** + * Transform the tree into a tree with a different type of token + * + * @param + * The type of the new tree + * @param transformer + * The function to use to transform tokens + * @return A tree with the token types transformed + */ + public ITree + transformTree(Function 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 action); } -- cgit v1.2.3