From 674d9769821775484fe6913b93c650189fbedfed Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sat, 25 Mar 2017 14:07:24 -0400 Subject: General cleanup --- .../java/bjc/utils/parserutils/ShuntingYard.java | 43 +++++++++++++--------- .../utils/parserutils/delims/DelimiterGroup.java | 3 -- .../utils/parserutils/delims/StringDelimiter.java | 2 +- .../bjc/utils/parserutils/pratt/PrattParser.java | 2 - 4 files changed, 26 insertions(+), 24 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils') 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 2a0bdff..7fc3688 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -72,26 +72,26 @@ public class ShuntingYard { @Override public void accept(String token) { // Handle operators - if(operators.containsKey(token)) { + 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())); } // 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 stack.push(token); - } else if(StringUtils.containsOnly(token, "\\)")) { + } else if (StringUtils.containsOnly(token, "\\)")) { // Handle groups of parenthesis for multiple // nesting levels 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())); } @@ -119,7 +119,7 @@ public class ShuntingYard { operators = new FunctionalMap<>(); // 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); @@ -130,13 +130,15 @@ public class ShuntingYard { /** * Add an operator to the list of shuntable operators * - * @param operatorToken + * @param operator * The token representing the operator * @param precedence * The precedence of the operator to add */ public void addOp(String operator, int precedence) { - // Create the precedence marker + /* + * Create the precedence marker + */ IPrecedent prec = IPrecedent.newSimplePrecedent(precedence); this.addOp(operator, prec); @@ -145,18 +147,23 @@ public class ShuntingYard { /** * Add an operator to the list of shuntable operators * - * @param operatorToken + * @param operator * The token representing the operator + * * @param precedence * The precedence of the operator */ public void addOp(String operator, IPrecedent precedence) { - // Complain about trying to add an incorrect operator - if(operator == null) + /* + * Complain about trying to add an incorrect operator + */ + 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 + /* + * Add the operator to the ones we handle + */ operators.put(operator, precedence); } @@ -165,7 +172,7 @@ public class ShuntingYard { boolean exists = operators.containsKey(right); // If it doesn't, the left is higher precedence. - if(!exists) return false; + if (!exists) return false; // Get the precedence of operators int rightPrecedence = operators.get(right).getPrecedence(); @@ -186,9 +193,9 @@ public class ShuntingYard { */ public IList postfix(IList input, Function transformer) { // 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 IList output = new FunctionalList<>(); @@ -210,13 +217,13 @@ public class ShuntingYard { /** * Remove an operator from the list of shuntable operators * - * @param token + * @param operator * The token representing the operator. If null, remove * all operators */ public void removeOp(String operator) { // Check if we want to remove all operators - if(operator == null) { + if (operator == null) { operators = new FunctionalMap<>(); } else { operators.remove(operator); diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java index 652b8f6..db6ae8c 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java @@ -431,9 +431,6 @@ public class DelimiterGroup { * * @param priority * The priority of this sub-group. - * - * @param contained - * Any sub-groups to enclose in this group. */ public void addSubgroup(T subgroup, int priority) { if(subgroup == null) { diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java index cbf99ee..6db1c98 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java @@ -12,7 +12,7 @@ public class StringDelimiter extends SequenceDelimiter { /** * Override of - * {@link SequenceDelimiter#delimitSequence(Object, Object, Object...)} + * {@link SequenceDelimiter#delimitSequence(SequenceCharacteristics, Object...)} * for ease of use for strings. * * @param seq diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/PrattParser.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/PrattParser.java index e8543dc..20572e8 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/PrattParser.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/PrattParser.java @@ -36,8 +36,6 @@ public class PrattParser { /** * Create a new Pratt parser. * - * @param terminal - * The terminal symbol. */ public PrattParser() { leftCommands = new HashMap<>(); -- cgit v1.2.3