From b0516949d7577b809c75d7267df77bff2cdb078b Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 3 Oct 2016 09:11:55 -0400 Subject: Minor reorganization --- BJC-Utils2/src/main/java/bjc/utils/data/ITree.java | 189 ++++++++++++ .../bjc/utils/data/TopDownTransformResult.java | 30 ++ BJC-Utils2/src/main/java/bjc/utils/data/Tree.java | 336 +++++++++++++++++++++ .../src/main/java/bjc/utils/funcdata/ITree.java | 188 ------------ .../bjc/utils/funcdata/TopDownTransformResult.java | 30 -- .../src/main/java/bjc/utils/funcdata/Tree.java | 334 -------------------- .../bjc/utils/parserutils/TokenTransformer.java | 4 +- .../bjc/utils/parserutils/TreeConstructor.java | 2 +- 8 files changed, 558 insertions(+), 555 deletions(-) create mode 100644 BJC-Utils2/src/main/java/bjc/utils/data/ITree.java create mode 100644 BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java create mode 100644 BJC-Utils2/src/main/java/bjc/utils/data/Tree.java delete mode 100644 BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java delete mode 100644 BJC-Utils2/src/main/java/bjc/utils/funcdata/TopDownTransformResult.java delete mode 100644 BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java (limited to 'BJC-Utils2/src/main/java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java b/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java new file mode 100644 index 0000000..7d5988f --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/data/ITree.java @@ -0,0 +1,189 @@ +package bjc.utils.data; + +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; + +import bjc.utils.funcdata.IList; +import bjc.utils.funcdata.bst.TreeLinearizationMethod; + +/** + * A node in a homogenous tree with a unlimited amount of children + * + * @author ben + * @param + * The type of data contained in the tree nodes + * + */ +public interface ITree { + /** + * Add a child to this node + * + * @param child + * The child to add to this node + */ + public void addChild(ITree child); + + /** + * Collapse a tree into a single version + * + * @param + * The intermediate type being folded + * @param + * The type that is the end result + * @param leafTransform + * The function to use to convert leaf values + * @param nodeCollapser + * 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 + * @return The final transformed state + */ + public ReturnedType collapse( + Function leafTransform, + 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 + * + * @param mapper + * The function to use to map values into trees + * @return A tree, with some nodes expanded into trees + */ + public ITree flatMapTree( + Function> mapper); + + /** + * Get the specified child of this tree + * + * @param childNo + * The number of the child to get + * @return The specified child of this tree + */ + default ITree getChild(int childNo) { + return transformChild(childNo, (child) -> child); + } + + /** + * Get a count of the number of direct children this node has + * + * @return The number of direct children this node has + */ + public int getChildrenCount(); + + /** + * Get the data stored in this node + * + * @return The data stored in this node + */ + default ContainedType getHead() { + return transformHead((head) -> head); + } + + /** + * Rebuild the tree with the same structure, but different nodes + * + * @param + * The type of the new tree + * @param leafTransformer + * The function to use to transform leaf tokens + * @param operatorTransformer + * The function to use to transform internal tokens + * @return The tree, with the nodes changed + */ + public ITree rebuildTree( + 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 + * + * @param transformPicker + * The function to use to pick how to progress + * @param transformer + * The function used to transform picked subtrees + * @return The tree with the transform applied to picked subtrees + */ + public ITree topDownTransform( + Function transformPicker, + UnaryOperator> transformer); + + /** + * 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); + + /** + * 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); + + /** + * 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); +} diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java b/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java new file mode 100644 index 0000000..a2448d2 --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/data/TopDownTransformResult.java @@ -0,0 +1,30 @@ +package bjc.utils.data; + +/** + * Represents the results for doing a top-down transform of a tree + * + * @author ben + * + */ +public enum TopDownTransformResult { + /** + * Do not do anything to this node, and ignore it's children + */ + SKIP, + /** + * Transform this node, and don't touch its children + */ + TRANSFORM, + /** + * Ignore this node, and traverse its children + */ + PASSTHROUGH, + /** + * Traverse this nodes children, then transform it + */ + PUSHDOWN, + /** + * Transform this node, then traverse its children + */ + PULLUP; +} diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java b/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java new file mode 100644 index 0000000..46fb1a6 --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Tree.java @@ -0,0 +1,336 @@ +package bjc.utils.data; + +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; + +import bjc.utils.funcdata.FunctionalList; +import bjc.utils.funcdata.IList; +import bjc.utils.funcdata.bst.TreeLinearizationMethod; +import bjc.utils.funcutils.StringUtils; + +/** + * A node in a homogenous tree. + * + * @author ben + * + * @param + */ +public class Tree implements ITree { + private ContainedType data; + private IList> children; + + private boolean hasChildren; + + private int childCount = 0; + + /** + * Create a new leaf node in a tree + * + * @param leafToken + * The data to store as a leaf node + */ + public Tree(ContainedType leafToken) { + data = leafToken; + + hasChildren = false; + } + + /** + * Create a new tree node with the specified children + * + * @param leafToken + * The data to hold in this node + * @param childrn + * A list of children for this node + */ + public Tree(ContainedType leafToken, + IList> childrn) { + data = leafToken; + + hasChildren = true; + + childCount = childrn.getSize(); + + children = childrn; + } + + /** + * Create a new tree node with the specified children + * + * @param leafToken + * The data to hold in this node + * @param childrn + * A list of children for this node + */ + @SafeVarargs + public Tree(ContainedType leafToken, ITree... childrn) { + data = leafToken; + + hasChildren = true; + + childCount = 0; + + children = new FunctionalList<>(); + + for (ITree child : childrn) { + children.add(child); + + childCount++; + } + } + + @Override + public void addChild(ITree child) { + if (hasChildren == false) { + hasChildren = true; + + children = new FunctionalList<>(); + } + + childCount++; + + children.add(child); + } + + @Override + public ReturnedType collapse( + Function leafTransform, + Function, NewType>> nodeCollapser, + Function resultTransformer) { + + return resultTransformer + .apply(internalCollapse(leafTransform, nodeCollapser)); + } + + @Override + public void doForChildren(Consumer> action) { + children.forEach(action); + } + + @Override + public ITree flatMapTree( + Function> mapper) { + if (hasChildren) { + ITree flatMappedData = mapper.apply(data); + + children.map((child) -> child.flatMapTree(mapper)) + .forEach((child) -> flatMappedData.addChild(child)); + + return flatMappedData; + } + + return mapper.apply(data); + } + + @Override + public int getChildrenCount() { + return childCount; + } + + protected NewType internalCollapse( + Function leafTransform, + Function, NewType>> nodeCollapser) { + if (hasChildren) { + Function, + NewType> nodeTransformer = nodeCollapser.apply(data); + + IList collapsedChildren = (IList) children + .map((child) -> { + return child.collapse(leafTransform, nodeCollapser, + (subTreeVal) -> subTreeVal); + }); + + return nodeTransformer.apply(collapsedChildren); + } + + return leafTransform.apply(data); + } + + protected void internalToString(StringBuilder builder, int indentLevel, + boolean initial) { + if (!initial) { + StringUtils.indentNLevels(builder, indentLevel); + } + + builder.append("Node: "); + builder.append(data == null ? "(null)" : data.toString()); + builder.append("\n"); + + if (hasChildren) { + children.forEach((child) -> { + ((Tree) child).internalToString(builder, + indentLevel + 2, false); + }); + } + } + + @Override + public ITree rebuildTree( + Function leafTransformer, + Function operatorTransformer) { + if (hasChildren) { + IList> mappedChildren = children + .map((child) -> { + return child.rebuildTree(leafTransformer, + operatorTransformer); + }); + + return new Tree<>(operatorTransformer.apply(data), + mappedChildren); + } + + return new Tree<>(leafTransformer.apply(data)); + } + + @Override + public void selectiveTransform(Predicate nodePicker, + UnaryOperator transformer) { + if (hasChildren) { + children.forEach((child) -> child + .selectiveTransform(nodePicker, transformer)); + } else { + data = transformer.apply(data); + } + } + + @Override + public ITree topDownTransform( + Function transformPicker, + UnaryOperator> transformer) { + TopDownTransformResult transformResult = transformPicker + .apply(data); + + switch (transformResult) { + case PASSTHROUGH: + ITree result = new Tree<>(data); + + if (hasChildren) { + children.forEach((child) -> { + result.addChild(child.topDownTransform( + transformPicker, transformer)); + }); + } + + return result; + case SKIP: + return this; + case TRANSFORM: + return transformer.apply(this); + case PUSHDOWN: + result = new Tree<>(data); + + if (hasChildren) { + children.forEach((child) -> { + result.addChild(child.topDownTransform( + transformPicker, transformer)); + }); + } + + return transformer.apply(result); + case PULLUP: + ITree intermediateResult = transformer + .apply(this); + + result = new Tree<>(intermediateResult.getHead()); + + intermediateResult.doForChildren((child) -> { + result.addChild(child.topDownTransform(transformPicker, + transformer)); + }); + + return result; + default: + throw new IllegalArgumentException( + "Recieved unknown transform result " + + transformResult); + + } + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + internalToString(builder, 1, true); + + builder.deleteCharAt(builder.length() - 1); + + return builder.toString(); + } + + @Override + public TransformedType transformChild(int childNo, + Function, TransformedType> transformer) { + if (childNo < 0 || childNo > (childCount - 1)) { + throw new IllegalArgumentException( + "Child index #" + childNo + " is invalid"); + } + + return transformer.apply(children.getByIndex(childNo)); + } + + @Override + public TransformedType transformHead( + Function transformer) { + return transformer.apply(data); + } + + @Override + public ITree transformTree( + Function transformer) { + if (hasChildren) { + IList> transformedChildren = children + .map((child) -> child.transformTree(transformer)); + + return new Tree<>(transformer.apply(data), + transformedChildren); + } + + return new Tree<>(transformer.apply(data)); + } + + @Override + public void traverse(TreeLinearizationMethod linearizationMethod, + Consumer action) { + if (hasChildren) { + switch (linearizationMethod) { + case INORDER: + if (childCount != 2) { + throw new IllegalArgumentException( + "Can only do in-order traversal for binary trees."); + } + + children.getByIndex(0).traverse(linearizationMethod, + action); + + action.accept(data); + + children.getByIndex(1).traverse(linearizationMethod, + action); + break; + case POSTORDER: + children.forEach((child) -> child + .traverse(linearizationMethod, action)); + + action.accept(data); + break; + case PREORDER: + action.accept(data); + + children.forEach((child) -> child + .traverse(linearizationMethod, action)); + break; + default: + break; + + } + } else { + action.accept(data); + } + } +} diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java deleted file mode 100644 index c773f4e..0000000 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/ITree.java +++ /dev/null @@ -1,188 +0,0 @@ -package bjc.utils.funcdata; - -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; - -import bjc.utils.funcdata.bst.TreeLinearizationMethod; - -/** - * A node in a homogenous tree with a unlimited amount of children - * - * @author ben - * @param - * The type of data contained in the tree nodes - * - */ -public interface ITree { - /** - * Add a child to this node - * - * @param child - * The child to add to this node - */ - public void addChild(ITree child); - - /** - * Collapse a tree into a single version - * - * @param - * The intermediate type being folded - * @param - * The type that is the end result - * @param leafTransform - * The function to use to convert leaf values - * @param nodeCollapser - * 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 - * @return The final transformed state - */ - public ReturnedType collapse( - Function leafTransform, - 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 - * - * @param mapper - * The function to use to map values into trees - * @return A tree, with some nodes expanded into trees - */ - public ITree flatMapTree( - Function> mapper); - - /** - * Get the specified child of this tree - * - * @param childNo - * The number of the child to get - * @return The specified child of this tree - */ - default ITree getChild(int childNo) { - return transformChild(childNo, (child) -> child); - } - - /** - * Get a count of the number of direct children this node has - * - * @return The number of direct children this node has - */ - public int getChildrenCount(); - - /** - * Get the data stored in this node - * - * @return The data stored in this node - */ - default ContainedType getHead() { - return transformHead((head) -> head); - } - - /** - * Rebuild the tree with the same structure, but different nodes - * - * @param - * The type of the new tree - * @param leafTransformer - * The function to use to transform leaf tokens - * @param operatorTransformer - * The function to use to transform internal tokens - * @return The tree, with the nodes changed - */ - public ITree rebuildTree( - 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 - * - * @param transformPicker - * The function to use to pick how to progress - * @param transformer - * The function used to transform picked subtrees - * @return The tree with the transform applied to picked subtrees - */ - public ITree topDownTransform( - Function transformPicker, - UnaryOperator> transformer); - - /** - * 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); - - /** - * 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); - - /** - * 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); -} diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/TopDownTransformResult.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/TopDownTransformResult.java deleted file mode 100644 index 332c3c1..0000000 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/TopDownTransformResult.java +++ /dev/null @@ -1,30 +0,0 @@ -package bjc.utils.funcdata; - -/** - * Represents the results for doing a top-down transform of a tree - * - * @author ben - * - */ -public enum TopDownTransformResult { - /** - * Do not do anything to this node, and ignore it's children - */ - SKIP, - /** - * Transform this node, and don't touch its children - */ - TRANSFORM, - /** - * Ignore this node, and traverse its children - */ - PASSTHROUGH, - /** - * Traverse this nodes children, then transform it - */ - PUSHDOWN, - /** - * Transform this node, then traverse its children - */ - PULLUP; -} diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java deleted file mode 100644 index 68a0ae1..0000000 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java +++ /dev/null @@ -1,334 +0,0 @@ -package bjc.utils.funcdata; - -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; - -import bjc.utils.funcdata.bst.TreeLinearizationMethod; -import bjc.utils.funcutils.StringUtils; - -/** - * A node in a homogenous tree. - * - * @author ben - * - * @param - */ -public class Tree implements ITree { - private ContainedType data; - private IList> children; - - private boolean hasChildren; - - private int childCount = 0; - - /** - * Create a new leaf node in a tree - * - * @param leafToken - * The data to store as a leaf node - */ - public Tree(ContainedType leafToken) { - data = leafToken; - - hasChildren = false; - } - - /** - * Create a new tree node with the specified children - * - * @param leafToken - * The data to hold in this node - * @param childrn - * A list of children for this node - */ - public Tree(ContainedType leafToken, - IList> childrn) { - data = leafToken; - - hasChildren = true; - - childCount = childrn.getSize(); - - children = childrn; - } - - /** - * Create a new tree node with the specified children - * - * @param leafToken - * The data to hold in this node - * @param childrn - * A list of children for this node - */ - @SafeVarargs - public Tree(ContainedType leafToken, ITree... childrn) { - data = leafToken; - - hasChildren = true; - - childCount = 0; - - children = new FunctionalList<>(); - - for (ITree child : childrn) { - children.add(child); - - childCount++; - } - } - - @Override - public void addChild(ITree child) { - if (hasChildren == false) { - hasChildren = true; - - children = new FunctionalList<>(); - } - - childCount++; - - children.add(child); - } - - @Override - public ReturnedType collapse( - Function leafTransform, - Function, NewType>> nodeCollapser, - Function resultTransformer) { - - return resultTransformer - .apply(internalCollapse(leafTransform, nodeCollapser)); - } - - @Override - public void doForChildren(Consumer> action) { - children.forEach(action); - } - - @Override - public ITree flatMapTree( - Function> mapper) { - if (hasChildren) { - ITree flatMappedData = mapper.apply(data); - - children.map((child) -> child.flatMapTree(mapper)) - .forEach((child) -> flatMappedData.addChild(child)); - - return flatMappedData; - } - - return mapper.apply(data); - } - - @Override - public int getChildrenCount() { - return childCount; - } - - protected NewType internalCollapse( - Function leafTransform, - Function, NewType>> nodeCollapser) { - if (hasChildren) { - Function, - NewType> nodeTransformer = nodeCollapser.apply(data); - - IList collapsedChildren = (IList) children - .map((child) -> { - return child.collapse(leafTransform, nodeCollapser, - (subTreeVal) -> subTreeVal); - }); - - return nodeTransformer.apply(collapsedChildren); - } - - return leafTransform.apply(data); - } - - protected void internalToString(StringBuilder builder, int indentLevel, - boolean initial) { - if (!initial) { - StringUtils.indentNLevels(builder, indentLevel); - } - - builder.append("Node: "); - builder.append(data == null ? "(null)" : data.toString()); - builder.append("\n"); - - if (hasChildren) { - children.forEach((child) -> { - ((Tree) child).internalToString(builder, - indentLevel + 2, false); - }); - } - } - - @Override - public ITree rebuildTree( - Function leafTransformer, - Function operatorTransformer) { - if (hasChildren) { - IList> mappedChildren = children - .map((child) -> { - return child.rebuildTree(leafTransformer, - operatorTransformer); - }); - - return new Tree<>(operatorTransformer.apply(data), - mappedChildren); - } - - return new Tree<>(leafTransformer.apply(data)); - } - - @Override - public void selectiveTransform(Predicate nodePicker, - UnaryOperator transformer) { - if (hasChildren) { - children.forEach((child) -> child - .selectiveTransform(nodePicker, transformer)); - } else { - data = transformer.apply(data); - } - } - - @Override - public ITree topDownTransform( - Function transformPicker, - UnaryOperator> transformer) { - TopDownTransformResult transformResult = transformPicker - .apply(data); - - switch (transformResult) { - case PASSTHROUGH: - ITree result = new Tree<>(data); - - if (hasChildren) { - children.forEach((child) -> { - result.addChild(child.topDownTransform( - transformPicker, transformer)); - }); - } - - return result; - case SKIP: - return this; - case TRANSFORM: - return transformer.apply(this); - case PUSHDOWN: - result = new Tree<>(data); - - if (hasChildren) { - children.forEach((child) -> { - result.addChild(child.topDownTransform( - transformPicker, transformer)); - }); - } - - return transformer.apply(result); - case PULLUP: - ITree intermediateResult = transformer - .apply(this); - - result = new Tree<>(intermediateResult.getHead()); - - intermediateResult.doForChildren((child) -> { - result.addChild(child.topDownTransform(transformPicker, - transformer)); - }); - - return result; - default: - throw new IllegalArgumentException( - "Recieved unknown transform result " - + transformResult); - - } - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - - internalToString(builder, 1, true); - - builder.deleteCharAt(builder.length() - 1); - - return builder.toString(); - } - - @Override - public TransformedType transformChild(int childNo, - Function, TransformedType> transformer) { - if (childNo < 0 || childNo > (childCount - 1)) { - throw new IllegalArgumentException( - "Child index #" + childNo + " is invalid"); - } - - return transformer.apply(children.getByIndex(childNo)); - } - - @Override - public TransformedType transformHead( - Function transformer) { - return transformer.apply(data); - } - - @Override - public ITree transformTree( - Function transformer) { - if (hasChildren) { - IList> transformedChildren = children - .map((child) -> child.transformTree(transformer)); - - return new Tree<>(transformer.apply(data), - transformedChildren); - } - - return new Tree<>(transformer.apply(data)); - } - - @Override - public void traverse(TreeLinearizationMethod linearizationMethod, - Consumer action) { - if (hasChildren) { - switch (linearizationMethod) { - case INORDER: - if (childCount != 2) { - throw new IllegalArgumentException( - "Can only do in-order traversal for binary trees."); - } - - children.getByIndex(0).traverse(linearizationMethod, - action); - - action.accept(data); - - children.getByIndex(1).traverse(linearizationMethod, - action); - break; - case POSTORDER: - children.forEach((child) -> child - .traverse(linearizationMethod, action)); - - action.accept(data); - break; - case PREORDER: - action.accept(data); - - children.forEach((child) -> child - .traverse(linearizationMethod, action)); - break; - default: - break; - - } - } else { - action.accept(data); - } - } -} diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenTransformer.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenTransformer.java index 7cfb9cd..149cbbf 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenTransformer.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenTransformer.java @@ -8,9 +8,9 @@ import java.util.function.UnaryOperator; import bjc.utils.data.IHolder; import bjc.utils.data.IPair; +import bjc.utils.data.ITree; import bjc.utils.data.Pair; -import bjc.utils.funcdata.ITree; -import bjc.utils.funcdata.Tree; +import bjc.utils.data.Tree; final class TokenTransformer implements Consumer { private final class OperatorHandler implements UnaryOperator< diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java index 5184fa6..2ddde9d 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java @@ -7,10 +7,10 @@ import java.util.function.Predicate; import bjc.utils.data.IHolder; import bjc.utils.data.IPair; +import bjc.utils.data.ITree; import bjc.utils.data.Identity; import bjc.utils.data.Pair; import bjc.utils.funcdata.IList; -import bjc.utils.funcdata.ITree; /** * Creates a parse tree from a postfix expression -- cgit v1.2.3