From 27bf571d6413c3cc6a5d664b5bddd38d21d7b1cd Mon Sep 17 00:00:00 2001 From: EVE Date: Mon, 13 Mar 2017 16:42:21 -0400 Subject: Formatting --- .../java/bjc/utils/parserutils/ShuntingYard.java | 43 +++++++++++----------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java') 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 fe046f4..19c1971 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -17,7 +17,7 @@ import bjc.utils.funcutils.StringUtils; * @author ben * * @param - * The type of tokens being shunted + * The type of tokens being shunted */ public class ShuntingYard { /** @@ -58,9 +58,9 @@ public class ShuntingYard { } private final class TokenShunter implements Consumer { - private IList output; - private Deque stack; - private Function transformer; + private IList output; + private Deque stack; + private Function transformer; public TokenShunter(IList outpt, Deque stack, Function transformer) { @@ -73,19 +73,21 @@ public class ShuntingYard { public void accept(String token) { // Handle operators if (operators.containsKey(token)) { - // Pop operators while there isn't a higher precedence one - while (!stack.isEmpty() - && isHigherPrec(token, stack.peek())) { + // Pop operators while there isn't a higher + // precedence one + while (!stack.isEmpty() && isHigherPrec(token, stack.peek())) { output.add(transformer.apply(stack.pop())); } // Put this operator onto the stack stack.push(token); } else if (StringUtils.containsOnly(token, "\\(")) { - // Handle groups of parenthesis for multiple nesting levels + // Handle groups of parenthesis for multiple + // nesting levels stack.push(token); } else if (StringUtils.containsOnly(token, "\\)")) { - // Handle groups of parenthesis for multiple nesting levels + // Handle groups of parenthesis for multiple + // nesting levels String swappedToken = token.replace(')', '('); // Remove tokens up to a matching parenthesis @@ -111,7 +113,7 @@ public class ShuntingYard { * Create a new shunting yard with a default set of operators * * @param configureBasics - * Whether or not basic math operators should be provided + * Whether or not basic math operators should be provided */ public ShuntingYard(boolean configureBasics) { operators = new FunctionalMap<>(); @@ -129,9 +131,9 @@ public class ShuntingYard { * Add an operator to the list of shuntable operators * * @param operatorToken - * The token representing the operator + * The token representing the operator * @param precedence - * The precedence of the operator to add + * The precedence of the operator to add */ public void addOp(String operator, int precedence) { // Create the precedence marker @@ -144,15 +146,15 @@ public class ShuntingYard { * Add an operator to the list of shuntable operators * * @param operatorToken - * The token representing the operator + * The token representing the operator * @param precedence - * The precedence of the operator + * The precedence of the operator */ public void addOp(String operator, IPrecedent precedence) { // Complain about trying to add an incorrect operator if (operator == null) { throw new NullPointerException("Operator must not be null"); - } else if(precedence == null) { + } else if (precedence == null) { throw new NullPointerException("Precedence must not be null"); } @@ -181,13 +183,12 @@ public class ShuntingYard { * Transform a string of tokens from infix notation to postfix * * @param input - * The string to transform + * The string to transform * @param transformer - * The function to use to transform strings to tokens + * The function to use to transform strings to tokens * @return A list of tokens in postfix notation */ - public IList postfix(IList input, - Function transformer) { + public IList postfix(IList input, Function transformer) { // Check our input if (input == null) { throw new NullPointerException("Input must not be null"); @@ -216,8 +217,8 @@ public class ShuntingYard { * Remove an operator from the list of shuntable operators * * @param token - * The token representing the operator. If null, remove all - * operators + * The token representing the operator. If null, remove + * all operators */ public void removeOp(String operator) { // Check if we want to remove all operators -- cgit v1.2.3