summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2020-04-13 18:40:41 -0400
committerBen Culkin <scorpress@gmail.com>2020-04-13 18:40:41 -0400
commitd4ca769e542b2489b1e23cfcbdc3a0b7275b87cd (patch)
tree1653a7399f97fb0c63ce62e3f60fd830d5c37f70 /base/src/main/java/bjc/utils/parserutils/ShuntingYard.java
parent2ac2e31a56ae59ee582e43a90c3495f86dd9ee7a (diff)
Cleanup pass
Cleanup pass to uniformize things
Diffstat (limited to 'base/src/main/java/bjc/utils/parserutils/ShuntingYard.java')
-rw-r--r--base/src/main/java/bjc/utils/parserutils/ShuntingYard.java43
1 files changed, 22 insertions, 21 deletions
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 <TokenType>
- * The type of tokens being shunted.
+ * The type of tokens being shunted.
*/
public class ShuntingYard<TokenType> {
/**
@@ -65,8 +65,8 @@ 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<>();
@@ -86,10 +86,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) {
/*
@@ -104,10 +104,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.
+ * The precedence of the operator.
*/
public void addOp(final String operator, final IPrecedent precedence) {
/*
@@ -115,7 +115,8 @@ public class ShuntingYard<TokenType> {
*/
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<TokenType> {
/*
* 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<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.
*/
- public IList<TokenType> postfix(final IList<String> input, final Function<String, TokenType> transformer) {
+ public IList<TokenType> postfix(final IList<String> input,
+ final Function<String, TokenType> 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<TokenType> {
*/
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<TokenType> {
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<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) {
/*