Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConcurrencyTest was not being executed, cleanup #85

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
22 changes: 11 additions & 11 deletions src/main/java/net/objecthunter/exp4j/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.objecthunter.exp4j.tokenizer.NumberToken;
import net.objecthunter.exp4j.tokenizer.OperatorToken;
import net.objecthunter.exp4j.tokenizer.Token;
import net.objecthunter.exp4j.tokenizer.TokenType;
import net.objecthunter.exp4j.tokenizer.VariableToken;

import java.util.ArrayList;
Expand All @@ -32,7 +33,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -100,7 +100,7 @@ public Expression setVariables(Map<String, Double> variables) {
public Set<String> getVariableNames() {
final Set<String> variables = new HashSet<String>();
for (final Token t: tokens) {
if (t.getType() == Token.TOKEN_VARIABLE)
if (t.getType() == TokenType.VARIABLE)
variables.add(((VariableToken)t).getName());
}
return variables;
Expand All @@ -111,7 +111,7 @@ public ValidationResult validate(boolean checkVariablesSet) {
if (checkVariablesSet) {
/* check that all vars have a value set */
for (final Token t : this.tokens) {
if (t.getType() == Token.TOKEN_VARIABLE) {
if (t.getType() == TokenType.VARIABLE) {
final String var = ((VariableToken) t).getName();
if (!variables.containsKey(var)) {
errors.add("The setVariable '" + var + "' has not been set");
Expand All @@ -129,11 +129,11 @@ public ValidationResult validate(boolean checkVariablesSet) {
int count = 0;
for (Token tok : this.tokens) {
switch (tok.getType()) {
case Token.TOKEN_NUMBER:
case Token.TOKEN_VARIABLE:
case TokenType.NUMBER:
case TokenType.VARIABLE:
count++;
break;
case Token.TOKEN_FUNCTION:
case TokenType.FUNCTION:
final Function func = ((FunctionToken) tok).getFunction();
final int argsNum = func.getNumArguments();
if (argsNum > count) {
Expand All @@ -146,7 +146,7 @@ public ValidationResult validate(boolean checkVariablesSet) {
count++;
}
break;
case Token.TOKEN_OPERATOR:
case TokenType.OPERATOR:
Operator op = ((OperatorToken) tok).getOperator();
if (op.getNumOperands() == 2) {
count--;
Expand Down Expand Up @@ -182,16 +182,16 @@ public double evaluate() {
final ArrayStack output = new ArrayStack();
for (int i = 0; i < tokens.length; i++) {
Token t = tokens[i];
if (t.getType() == Token.TOKEN_NUMBER) {
if (t.getType() == TokenType.NUMBER) {
output.push(((NumberToken) t).getValue());
} else if (t.getType() == Token.TOKEN_VARIABLE) {
} else if (t.getType() == TokenType.VARIABLE) {
final String name = ((VariableToken) t).getName();
final Double value = this.variables.get(name);
if (value == null) {
throw new IllegalArgumentException("No value has been set for the setVariable '" + name + "'.");
}
output.push(value);
} else if (t.getType() == Token.TOKEN_OPERATOR) {
} else if (t.getType() == TokenType.OPERATOR) {
OperatorToken op = (OperatorToken) t;
if (output.size() < op.getOperator().getNumOperands()) {
throw new IllegalArgumentException("Invalid number of operands available for '" + op.getOperator().getSymbol() + "' operator");
Expand All @@ -206,7 +206,7 @@ public double evaluate() {
double arg = output.pop();
output.push(op.getOperator().apply(arg));
}
} else if (t.getType() == Token.TOKEN_FUNCTION) {
} else if (t.getType() == TokenType.FUNCTION) {
FunctionToken func = (FunctionToken) t;
final int numArguments = func.getFunction().getNumArguments();
if (output.size() < numArguments) {
Expand Down
Loading