diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-18 19:56:32 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-18 19:56:32 -0400 |
| commit | b4f5f98c0aa7fc892e96771ff2df729e61c21f74 (patch) | |
| tree | 09820cc267577c295be7bf33dc5deabf662cb37c /BJC-Utils2/src/main | |
| parent | 7c12fd8fe169944152ca73f0da4e8fe8e280f648 (diff) | |
Minor code changes
Diffstat (limited to 'BJC-Utils2/src/main')
8 files changed, 277 insertions, 252 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java index 70d04cc..735c664 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalList.java @@ -182,8 +182,8 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> { // Get the iterator for the other list Iterator<T> rightIterator = rightList.toIterable().iterator(); - for (Iterator<E> leftIterator = wrappedList - .iterator(); leftIterator.hasNext() + for (Iterator<E> leftIterator = + wrappedList.iterator(); leftIterator.hasNext() && rightIterator.hasNext();) { // Add the transformed items to the result list E leftVal = leftIterator.next(); @@ -228,18 +228,18 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> { * Function) */ @Override - public <T> IFunctionalList<T> flatMap( - Function<E, IFunctionalList<T>> elementExpander) { + public <T> IFunctionalList<T> + flatMap(Function<E, IFunctionalList<T>> elementExpander) { if (elementExpander == null) { throw new NullPointerException("Expander must not be null"); } - IFunctionalList<T> returnedList = new FunctionalList<>( - this.wrappedList.size()); + IFunctionalList<T> returnedList = + new FunctionalList<>(this.wrappedList.size()); forEach(element -> { - IFunctionalList<T> expandedElement = elementExpander - .apply(element); + IFunctionalList<T> expandedElement = + elementExpander.apply(element); if (expandedElement == null) { throw new NullPointerException( @@ -370,8 +370,8 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> { throw new NullPointerException("Transformer must be not null"); } - IFunctionalList<T> returnedList = new FunctionalList<>( - this.wrappedList.size()); + IFunctionalList<T> returnedList = + new FunctionalList<>(this.wrappedList.size()); forEach(element -> { // Add the transformed item to the result @@ -388,8 +388,8 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> { * IFunctionalList) */ @Override - public <T> IFunctionalList<IPair<E, T>> pairWith( - IFunctionalList<T> rightList) { + public <T> IFunctionalList<IPair<E, T>> + pairWith(IFunctionalList<T> rightList) { return combineWith(rightList, Pair<E, T>::new); } @@ -399,8 +399,8 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> { * @see bjc.utils.funcdata.IFunctionalList#partition(int) */ @Override - public IFunctionalList<IFunctionalList<E>> partition( - int numberPerPartition) { + public IFunctionalList<IFunctionalList<E>> + partition(int numberPerPartition) { if (numberPerPartition < 1 || numberPerPartition > wrappedList.size()) { throw new IllegalArgumentException("" + numberPerPartition @@ -408,11 +408,12 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> { + wrappedList.size()); } - IFunctionalList<IFunctionalList<E>> returnedList = new FunctionalList<>(); + IFunctionalList<IFunctionalList<E>> returnedList = + new FunctionalList<>(); // The current partition being filled - IHolder<IFunctionalList<E>> currentPartition = new Identity<>( - new FunctionalList<>()); + IHolder<IFunctionalList<E>> currentPartition = + new Identity<>(new FunctionalList<>()); this.forEach((element) -> { if (isPartitionFull(numberPerPartition, currentPartition)) { @@ -595,4 +596,9 @@ public class FunctionalList<E> implements Cloneable, IFunctionalList<E> { public IFunctionalList<E> tail() { return new FunctionalList<>(wrappedList.subList(1, getSize())); } + + @Override + public void reverse() { + Collections.reverse(wrappedList); + } }
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java index f22df57..2c5d2ae 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java @@ -172,8 +172,8 @@ public interface IFunctionalList<ContainedType> { * The predicate to match by * @return A list containing all elements that match the predicate */ - IFunctionalList<ContainedType> getMatching( - Predicate<ContainedType> matchPredicate); + IFunctionalList<ContainedType> + getMatching(Predicate<ContainedType> matchPredicate); /** * Retrieve the size of the wrapped list @@ -200,8 +200,8 @@ public interface IFunctionalList<ContainedType> { * The function to apply to each element in the list * @return A new list containing the mapped elements of this list. */ - <MappedType> IFunctionalList<MappedType> map( - Function<ContainedType, MappedType> elementTransformer); + <MappedType> IFunctionalList<MappedType> + map(Function<ContainedType, MappedType> elementTransformer); /** * Zip two lists into a list of pairs @@ -214,8 +214,8 @@ public interface IFunctionalList<ContainedType> { * @return A list containing pairs of this element and the specified * list */ - <OtherType> IFunctionalList<IPair<ContainedType, OtherType>> pairWith( - IFunctionalList<OtherType> rightList); + <OtherType> IFunctionalList<IPair<ContainedType, OtherType>> + pairWith(IFunctionalList<OtherType> rightList); /** * Partition this list into a list of sublists @@ -224,8 +224,8 @@ public interface IFunctionalList<ContainedType> { * The size of elements to put into each one of the sublists * @return A list partitioned into partitions of size nPerPart */ - IFunctionalList<IFunctionalList<ContainedType>> partition( - int numberPerPartition); + IFunctionalList<IFunctionalList<ContainedType>> + partition(int numberPerPartition); /** * Prepend an item to the list @@ -325,10 +325,16 @@ public interface IFunctionalList<ContainedType> { * @return An iterable view onto the list */ Iterable<ContainedType> toIterable(); - + /** * Get the tail of this list (the list without the first element + * * @return The list without the first element */ public IFunctionalList<ContainedType> tail(); + + /** + * Reverse the contents of this list in place + */ + void reverse(); }
\ No newline at end of file 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); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java index cd43df7..b56ff48 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/Tree.java @@ -21,7 +21,7 @@ public class Tree<ContainedType> implements ITree<ContainedType> { private boolean hasChildren; - private int childCount; + private int childCount = 0; /** * Create a new leaf node in a tree @@ -43,21 +43,15 @@ public class Tree<ContainedType> implements ITree<ContainedType> { * @param childrn * A list of children for this node */ - @SafeVarargs - public Tree(ContainedType leafToken, ITree<ContainedType>... childrn) { + public Tree(ContainedType leafToken, + IFunctionalList<ITree<ContainedType>> childrn) { data = leafToken; hasChildren = true; - childCount = 0; - - children = new FunctionalList<>(); - - for (ITree<ContainedType> child : childrn) { - children.add(child); + childCount = childrn.getSize(); - childCount++; - } + children = childrn; } /** @@ -68,15 +62,21 @@ public class Tree<ContainedType> implements ITree<ContainedType> { * @param childrn * A list of children for this node */ - public Tree(ContainedType leafToken, - IFunctionalList<ITree<ContainedType>> childrn) { + @SafeVarargs + public Tree(ContainedType leafToken, ITree<ContainedType>... childrn) { data = leafToken; hasChildren = true; - childCount = childrn.getSize(); + childCount = 0; - children = childrn; + children = new FunctionalList<>(); + + for (ITree<ContainedType> child : childrn) { + children.add(child); + + childCount++; + } } @Override @@ -93,28 +93,6 @@ public class Tree<ContainedType> implements ITree<ContainedType> { } @Override - public <TransformedType> TransformedType transformHead( - Function<ContainedType, TransformedType> transformer) { - return transformer.apply(data); - } - - @Override - public int getChildrenCount() { - return childCount; - } - - @Override - public <TransformedType> TransformedType transformChild(int childNo, - Function<ITree<ContainedType>, TransformedType> transformer) { - if (childNo < 0 || childNo > (childCount - 1)) { - throw new IllegalArgumentException( - "Child index #" + childNo + " is invalid"); - } - - return transformer.apply(children.getByIndex(childNo)); - } - - @Override public <NewType, ReturnedType> ReturnedType collapse( Function<ContainedType, NewType> leafTransform, Function<ContainedType, Function<IFunctionalList<NewType>, NewType>> nodeCollapser, @@ -124,23 +102,9 @@ public class Tree<ContainedType> implements ITree<ContainedType> { .apply(internalCollapse(leafTransform, nodeCollapser)); } - protected <NewType> NewType internalCollapse( - Function<ContainedType, NewType> leafTransform, - Function<ContainedType, Function<IFunctionalList<NewType>, NewType>> nodeCollapser) { - if (hasChildren) { - Function<IFunctionalList<NewType>, NewType> nodeTransformer = - nodeCollapser.apply(data); - - IFunctionalList<NewType> collapsedChildren = - children.map((child) -> { - return child.collapse(leafTransform, nodeCollapser, - (subTreeVal) -> subTreeVal); - }); - - return nodeTransformer.apply(collapsedChildren); - } - - return leafTransform.apply(data); + @Override + public void doForChildren(Consumer<ITree<ContainedType>> action) { + children.forEach(action); } @Override @@ -159,68 +123,44 @@ public class Tree<ContainedType> implements ITree<ContainedType> { } @Override - public void selectiveTransform(Predicate<ContainedType> nodePicker, - UnaryOperator<ContainedType> transformer) { - if (hasChildren) { - children.forEach((child) -> child - .selectiveTransform(nodePicker, transformer)); - } else { - data = transformer.apply(data); - } + public int getChildrenCount() { + return childCount; } - @Override - public <MappedType> ITree<MappedType> transformTree( - Function<ContainedType, MappedType> transformer) { + protected <NewType> NewType internalCollapse( + Function<ContainedType, NewType> leafTransform, + Function<ContainedType, Function<IFunctionalList<NewType>, NewType>> nodeCollapser) { if (hasChildren) { - IFunctionalList<ITree<MappedType>> transformedChildren = - children.map( - (child) -> child.transformTree(transformer)); + Function<IFunctionalList<NewType>, NewType> nodeTransformer = + nodeCollapser.apply(data); - return new Tree<>(transformer.apply(data), - transformedChildren); + IFunctionalList<NewType> collapsedChildren = + children.map((child) -> { + return child.collapse(leafTransform, nodeCollapser, + (subTreeVal) -> subTreeVal); + }); + + return nodeTransformer.apply(collapsedChildren); } - return new Tree<>(transformer.apply(data)); + return leafTransform.apply(data); } - @Override - public void traverse(TreeLinearizationMethod linearizationMethod, - Consumer<ContainedType> 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); + protected void internalToString(StringBuilder builder, int indentLevel, + boolean initial) { + if (!initial) { + StringUtils.indentNLevels(builder, indentLevel); + } - children.forEach((child) -> child - .traverse(linearizationMethod, action)); - break; - default: - break; + builder.append("Node: "); + builder.append(data == null ? "(null)" : data.toString()); + builder.append("\n"); - } - } else { - action.accept(data); + if (hasChildren) { + children.forEach((child) -> { + ((Tree<ContainedType>) child).internalToString(builder, + indentLevel + 2, false); + }); } } @@ -243,31 +183,13 @@ public class Tree<ContainedType> implements ITree<ContainedType> { } @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - - internalToString(builder, 1, true); - - builder.deleteCharAt(builder.length() - 1); - - return builder.toString(); - } - - 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"); - + public void selectiveTransform(Predicate<ContainedType> nodePicker, + UnaryOperator<ContainedType> transformer) { if (hasChildren) { - children.forEach((child) -> { - ((Tree<ContainedType>) child).internalToString(builder, - indentLevel + 2, false); - }); + children.forEach((child) -> child + .selectiveTransform(nodePicker, transformer)); + } else { + data = transformer.apply(data); } } @@ -312,4 +234,87 @@ public class Tree<ContainedType> implements ITree<ContainedType> { } } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + internalToString(builder, 1, true); + + builder.deleteCharAt(builder.length() - 1); + + return builder.toString(); + } + + @Override + public <TransformedType> TransformedType transformChild(int childNo, + Function<ITree<ContainedType>, 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> TransformedType transformHead( + Function<ContainedType, TransformedType> transformer) { + return transformer.apply(data); + } + + @Override + public <MappedType> ITree<MappedType> transformTree( + Function<ContainedType, MappedType> transformer) { + if (hasChildren) { + IFunctionalList<ITree<MappedType>> 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<ContainedType> 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/funcutils/StringUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java index c58a42b..1d1838e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java @@ -1,5 +1,7 @@ package bjc.utils.funcutils; +import java.util.Deque; + /** * Utility methods for operations on strings * @@ -71,4 +73,8 @@ public class StringUtils { builder.append("\t"); } } + + public static <ContainedType> String printDeque(Deque<ContainedType> queuedTrees) { + return queuedTrees.isEmpty() ? "(none)" : queuedTrees.toString(); + } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java index 9c7618b..0e34b97 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -87,7 +87,9 @@ public class ShuntingYard<E> { stack.push(token); } else if (StringUtils.containsOnly(token, "\\)")) { // Handle groups of parenthesis for multiple nesting levels - while (stack.peek().equals(token.replace(')', '('))) { + String swappedToken = token.replace(')', '('); + + while (!stack.peek().equals(swappedToken)) { output.add(transform.apply(stack.pop())); } @@ -98,21 +100,6 @@ public class ShuntingYard<E> { } } - private static boolean shouldConfigureBasicOperators = true; - - /** - * Set whether the shunter should configure the four basic math - * operators - * - * @param configureBasicOperators - * Whether or not the four basic math operators should be - * configured - */ - public static void setBasicOperatorConfiguration( - boolean configureBasicOperators) { - shouldConfigureBasicOperators = configureBasicOperators; - } - /** * Holds all the shuntable operations */ @@ -120,11 +107,12 @@ public class ShuntingYard<E> { /** * Create a new shunting yard with a default set of operators + * @param configureBasics Whether or not basic math operators should be provided */ - public ShuntingYard() { + public ShuntingYard(boolean configureBasics) { operators = new FunctionalMap<>(); - if (shouldConfigureBasicOperators) { + if (configureBasics) { operators.put("+", Operator.ADD); operators.put("-", Operator.SUBTRACT); operators.put("*", Operator.MULTIPLY); @@ -165,11 +153,15 @@ public class ShuntingYard<E> { String rightOperator) { boolean operatorExists = operators.containsKey(rightOperator); + if (!operatorExists) { + return false; + } + boolean hasHigherPrecedence = operators.get(rightOperator).getPrecedence() >= operators .get(leftOperator).getPrecedence(); - return (operatorExists && hasHigherPrecedence); + return hasHigherPrecedence; } /** 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 4db5e76..c88763f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenTransformer.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenTransformer.java @@ -11,6 +11,7 @@ import bjc.utils.data.IPair; import bjc.utils.data.Pair; import bjc.utils.funcdata.ITree; import bjc.utils.funcdata.Tree; +import bjc.utils.funcutils.StringUtils; final class TokenTransformer<T> implements Consumer<T> { private final class OperatorHandler @@ -34,7 +35,8 @@ final class TokenTransformer<T> implements Consumer<T> { ITree<T> newAST; if (isSpecialOperator.test(element)) { - newAST = handleSpecialOperator.apply(queuedASTs); + newAST = handleSpecialOperator.apply(element) + .apply(queuedASTs); } else { if (queuedASTs.size() < 2) { throw new IllegalStateException( @@ -56,15 +58,15 @@ final class TokenTransformer<T> implements Consumer<T> { } } - private IHolder<IPair<Deque<ITree<T>>, ITree<T>>> initialState; - private Predicate<T> operatorPredicate; - private Predicate<T> isSpecialOperator; - private Function<Deque<ITree<T>>, ITree<T>> handleSpecialOperator; + private IHolder<IPair<Deque<ITree<T>>, ITree<T>>> initialState; + private Predicate<T> operatorPredicate; + private Predicate<T> isSpecialOperator; + private Function<T, Function<Deque<ITree<T>>, ITree<T>>> handleSpecialOperator; public TokenTransformer( IHolder<IPair<Deque<ITree<T>>, ITree<T>>> initialState, Predicate<T> operatorPredicate, Predicate<T> isSpecialOperator, - Function<Deque<ITree<T>>, ITree<T>> handleSpecialOperator) { + Function<T, Function<Deque<ITree<T>>, ITree<T>>> handleSpecialOperator) { this.initialState = initialState; this.operatorPredicate = operatorPredicate; this.isSpecialOperator = isSpecialOperator; 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 efd0394..152d4d9 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java @@ -65,7 +65,7 @@ public class TreeConstructor { */ public static <T> ITree<T> constructTree(IFunctionalList<T> tokens, Predicate<T> operatorPredicate, Predicate<T> isSpecialOperator, - Function<Deque<ITree<T>>, ITree<T>> handleSpecialOperator) { + Function<T, Function<Deque<ITree<T>>, ITree<T>>> handleSpecialOperator) { if (tokens == null) { throw new NullPointerException("Tokens must not be null"); } else if (operatorPredicate == null) { |
