From d4ca769e542b2489b1e23cfcbdc3a0b7275b87cd Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:40:41 -0400 Subject: Cleanup pass Cleanup pass to uniformize things --- .../java/bjc/utils/parserutils/ShuntingYard.java | 43 +++++++++++----------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'base/src/main/java/bjc/utils/parserutils/ShuntingYard.java') diff --git a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java index bf332f5..2418517 100644 --- a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -16,7 +16,7 @@ import bjc.utils.funcutils.StringUtils; * @author ben * * @param - * The type of tokens being shunted. + * The type of tokens being shunted. */ public class ShuntingYard { /** @@ -65,8 +65,8 @@ 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(final boolean configureBasics) { operators = new FunctionalMap<>(); @@ -86,10 +86,10 @@ public class ShuntingYard { * 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) { /* @@ -104,10 +104,10 @@ public class ShuntingYard { * 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) { /* @@ -115,7 +115,8 @@ public class ShuntingYard { */ 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 @@ -133,7 +134,8 @@ public class ShuntingYard { /* * If it doesn't, the left is higher precedence. */ - if (!exists) return false; + if (!exists) + return false; /* * Get the precedence of operators @@ -151,20 +153,22 @@ 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(final IList input, final Function transformer) { + public IList postfix(final IList input, + final Function transformer) { /* * Check our input */ 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 @@ -182,8 +186,7 @@ public class ShuntingYard { */ if (operators.containsKey(token)) { /* - * Pop operators while there isn't a higher - * precedence one + * Pop operators while there isn't a higher precedence one */ while (!stack.isEmpty() && isHigherPrec(token, stack.peek())) { output.add(transformer.apply(stack.pop())); @@ -195,14 +198,12 @@ public class ShuntingYard { 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 */ final String swappedToken = token.replace(')', '('); @@ -236,8 +237,8 @@ public class ShuntingYard { * 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) { /* -- cgit v1.2.3