diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2018-02-12 22:45:04 -0500 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2018-02-12 22:45:04 -0500 |
| commit | df94066e3af02ff02d5ab4d033a3d603f743234c (patch) | |
| tree | 168a1edaf58d386c175ffb601e9d4da8e13d31e2 /base/src/main/java/bjc/utils/parserutils/ShuntingYard.java | |
| parent | ae51c587c53f7ca311e556e3cbd0c5566d6c2843 (diff) | |
Formatting pass
Diffstat (limited to 'base/src/main/java/bjc/utils/parserutils/ShuntingYard.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/parserutils/ShuntingYard.java | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java index a1b5feb..a0b1249 100644 --- a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -17,7 +17,7 @@ import bjc.utils.funcutils.StringUtils; * @author ben * * @param <TokenType> - * The type of tokens being shunted. + * The type of tokens being shunted. */ public class ShuntingYard<TokenType> { /** @@ -77,11 +77,12 @@ public class ShuntingYard<TokenType> { /* * Handle operators */ - if (operators.containsKey(token)) { - /* - * Pop operators while there isn't a higher precedence one + if(operators.containsKey(token)) { + /* + * Pop operators while there isn't a higher + * precedence one */ - while (!stack.isEmpty() && isHigherPrec(token, stack.peek())) { + while(!stack.isEmpty() && isHigherPrec(token, stack.peek())) { output.add(transformer.apply(stack.pop())); } @@ -89,21 +90,23 @@ public class ShuntingYard<TokenType> { * Put this operator onto the stack */ stack.push(token); - } else if (StringUtils.containsOnly(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, "\\)")) { + } else if(StringUtils.containsOnly(token, "\\)")) { /* - * Handle groups of parenthesis for multiple nesting levels + * Handle groups of parenthesis for multiple + * nesting levels */ final String swappedToken = token.replace(')', '('); /* * Remove tokens up to a matching parenthesis */ - while (!stack.peek().equals(swappedToken)) { + while(!stack.peek().equals(swappedToken)) { output.add(transformer.apply(stack.pop())); } @@ -129,8 +132,7 @@ public class ShuntingYard<TokenType> { * 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(final boolean configureBasics) { operators = new FunctionalMap<>(); @@ -138,7 +140,7 @@ public class ShuntingYard<TokenType> { /* * Add basic operators if we're configured to do so */ - if (configureBasics) { + if(configureBasics) { operators.put("+", Operator.ADD); operators.put("-", Operator.SUBTRACT); operators.put("*", Operator.MULTIPLY); @@ -150,10 +152,10 @@ public class ShuntingYard<TokenType> { * Add an operator to the list of shuntable operators. * * @param operator - * 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(final String operator, final int precedence) { /* @@ -168,18 +170,18 @@ public class ShuntingYard<TokenType> { * Add an operator to the list of shuntable operators. * * @param operator - * 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(final String operator, final IPrecedent precedence) { /* * Complain about trying to add an incorrect operator */ - if (operator == null) + if(operator == null) throw new NullPointerException("Operator must not be null"); - else if (precedence == null) throw new NullPointerException("Precedence must not be null"); + else if(precedence == null) throw new NullPointerException("Precedence must not be null"); /* * Add the operator to the ones we handle @@ -196,7 +198,7 @@ public class ShuntingYard<TokenType> { /* * If it doesn't, the left is higher precedence. */ - if (!exists) return false; + if(!exists) return false; /* * Get the precedence of operators @@ -214,10 +216,10 @@ public class ShuntingYard<TokenType> { * 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. */ @@ -225,9 +227,9 @@ public class ShuntingYard<TokenType> { /* * Check our input */ - if (input == null) + if(input == null) throw new NullPointerException("Input must not be null"); - else if (transformer == null) throw new NullPointerException("Transformer must not be null"); + else if(transformer == null) throw new NullPointerException("Transformer must not be null"); /* * Here's what we're handing back @@ -258,14 +260,14 @@ public class ShuntingYard<TokenType> { * Remove an operator from the list of shuntable operators. * * @param operator - * The token representing the operator. If null, remove - * all operators. + * The token representing the operator. If null, remove all + * operators. */ public void removeOp(final String operator) { /* * Check if we want to remove all operators */ - if (operator == null) { + if(operator == null) { operators = new FunctionalMap<>(); } else { operators.remove(operator); |
