From fb7d03388e298258563c22abda1bd46cdaf991b7 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 25 Apr 2016 22:11:28 -0400 Subject: General code cleanup, and some more GUI controls --- .../java/bjc/utils/parserutils/ShuntingYard.java | 46 +++++++++++----------- 1 file changed, 24 insertions(+), 22 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 636bf31..2ea23c6 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -16,10 +16,10 @@ import bjc.utils.funcutils.StringUtils; * * @author ben * - * @param + * @param * The type of tokens being shunted */ -public class ShuntingYard { +public class ShuntingYard { /** * A enum representing the fundamental operator types * @@ -32,17 +32,18 @@ public class ShuntingYard { */ ADD(1), /** - * Represents division + * Represents subtraction */ - DIVIDE(4), + SUBTRACT(2), + /** * Represents multiplication */ MULTIPLY(3), /** - * Represents subtraction + * Represents division */ - SUBTRACT(2); + DIVIDE(4); private final int precedence; @@ -62,12 +63,13 @@ public class ShuntingYard { } private final class TokenShunter implements Consumer { - private IFunctionalList output; - private Deque stack; - private Function transform; + private IFunctionalList output; + private Deque stack; + private Function transform; - public TokenShunter(IFunctionalList outpt, Deque stack, - Function transform) { + public TokenShunter(IFunctionalList outpt, + Deque stack, + Function transform) { this.output = outpt; this.stack = stack; this.transform = transform; @@ -159,11 +161,10 @@ public class ShuntingYard { return false; } - boolean hasHigherPrecedence = operators.get(rightOperator) - .getPrecedence() >= operators.get(leftOperator) - .getPrecedence(); + int rightPrecedence = operators.get(rightOperator).getPrecedence(); + int leftPrecedence = operators.get(leftOperator).getPrecedence(); - return hasHigherPrecedence; + return rightPrecedence >= leftPrecedence; } /** @@ -175,15 +176,16 @@ public class ShuntingYard { * The function to use to transform strings to tokens * @return A list of tokens in postfix notation */ - public IFunctionalList postfix(IFunctionalList input, - Function tokenTransformer) { + public IFunctionalList postfix( + IFunctionalList input, + Function tokenTransformer) { if (input == null) { throw new NullPointerException("Input must not be null"); } else if (tokenTransformer == null) { throw new NullPointerException("Transformer must not be null"); } - IFunctionalList output = new FunctionalList<>(); + IFunctionalList output = new FunctionalList<>(); Deque stack = new LinkedList<>(); @@ -199,14 +201,14 @@ public class ShuntingYard { /** * Remove an operator from the list of shuntable operators * - * @param tok + * @param token * The token representing the operator */ - public void removeOp(String tok) { - if (tok == null) { + public void removeOp(String token) { + if (token == null) { throw new NullPointerException("Token must not be null"); } - operators.remove(tok); + operators.remove(token); } } \ No newline at end of file -- cgit v1.2.3