summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java
diff options
context:
space:
mode:
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, 17 insertions, 26 deletions
diff --git a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java
index 2418517..f0475ff 100644
--- a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java
+++ b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java
@@ -6,8 +6,8 @@ import java.util.function.Function;
import bjc.funcdata.FunctionalList;
import bjc.funcdata.FunctionalMap;
-import bjc.funcdata.IList;
-import bjc.funcdata.IMap;
+import bjc.funcdata.ListEx;
+import bjc.funcdata.MapEx;
import bjc.utils.funcutils.StringUtils;
/**
@@ -25,7 +25,7 @@ public class ShuntingYard<TokenType> {
* @author ben
*
*/
- public static enum Operator implements IPrecedent {
+ public static enum Operator implements Precedent {
/**
* Represents addition.
*/
@@ -59,7 +59,7 @@ public class ShuntingYard<TokenType> {
/*
* Holds all the shuntable operations.
*/
- private IMap<String, IPrecedent> operators;
+ private MapEx<String, Precedent> operators;
/**
* Create a new shunting yard with a default set of operators.
@@ -95,7 +95,7 @@ public class ShuntingYard<TokenType> {
/*
* Create the precedence marker
*/
- final IPrecedent prec = IPrecedent.newSimplePrecedent(precedence);
+ final Precedent prec = Precedent.newSimplePrecedent(precedence);
this.addOp(operator, prec);
}
@@ -109,14 +109,12 @@ public class ShuntingYard<TokenType> {
* @param precedence
* The precedence of the operator.
*/
- public void addOp(final String operator, final IPrecedent precedence) {
+ public void addOp(final String operator, final Precedent precedence) {
/*
* 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");
+ if (operator == null) throw new NullPointerException("Operator must not be null");
+ else if (precedence == null) throw new NullPointerException("Precedence must not be null");
/*
* Add the operator to the ones we handle
@@ -140,8 +138,8 @@ public class ShuntingYard<TokenType> {
/*
* Get the precedence of operators
*/
- final int rightPrecedence = operators.get(right).getPrecedence();
- final int leftPrecedence = operators.get(left).getPrecedence();
+ final int rightPrecedence = operators.get(right).get().getPrecedence();
+ final int leftPrecedence = operators.get(left).get().getPrecedence();
/*
* Evaluate what we were asked
@@ -160,20 +158,18 @@ public class ShuntingYard<TokenType> {
*
* @return A list of tokens in postfix notation.
*/
- public IList<TokenType> postfix(final IList<String> input,
+ public ListEx<TokenType> postfix(final ListEx<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");
+ if (input == null) throw new NullPointerException("Input must not be null");
+ else if (transformer == null) throw new NullPointerException("Transformer must not be null");
/*
* Here's what we're handing back
*/
- final IList<TokenType> output = new FunctionalList<>();
+ final ListEx<TokenType> output = new FunctionalList<>();
/*
* The stack to put operators on
@@ -226,9 +222,7 @@ public class ShuntingYard<TokenType> {
}
}
- for (String token : stack) {
- output.add(transformer.apply(token));
- }
+ for (String token : stack) output.add(transformer.apply(token));
return output;
}
@@ -244,10 +238,7 @@ public class ShuntingYard<TokenType> {
/*
* Check if we want to remove all operators
*/
- if (operator == null) {
- operators = new FunctionalMap<>();
- } else {
- operators.remove(operator);
- }
+ if (operator == null) operators = new FunctionalMap<>();
+ else operators.remove(operator);
}
}