public Object evaluate(Object o) { if (o == null) { throw new IllegalArgumentException(); } else if (o instanceof Expression) { Expression e = (Expression) o; Operator operator = e.getOperator(); Evaluator evaluator = evaluators.get(operator); if (evaluator != null) return evaluator.evaluate(this, e); else throw new IllegalArgumentException(o.toString()); } else if (o instanceof Number) { return o; } else if (o instanceof String) { return o; } else if (o instanceof Boolean) { return o; } else { throw new IllegalArgumentException(); } }
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int minCount = 1; final int maxCount = -1; if (checkOperandCount(e, minCount, maxCount)) { Object o0 = ee.evaluate(e.getOperand(0)); if (o0 instanceof EvaluatorFunction) { EvaluatorFunction f = (EvaluatorFunction) o0; Object o1 = e.getOperand(1); if (o1 instanceof Expression) { Expression eArguments = (Expression) o1; if (eArguments.getOperator() == Operator.GROUP) { List<Object> arguments = new java.util.ArrayList<Object>(); for (Object operand : eArguments.getOperands()) { arguments.add(ee.evaluate(operand)); } return f.apply(ee.getState(), arguments); } else throw new IllegalStateException(); } else throw new IllegalStateException(); } else throw new IncompatibleOperandException(e, o0, EvaluatorFunction.class); } else throw new BadOperandCountException(e, minCount, maxCount); } else throw new BadOperatorException(e, "apply"); }
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { Operator operator = e.getOperator(); final int minCount = 2; final int maxCount = 2;
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int minCount = 2; final int maxCount = 2; if (checkOperandCount(e, minCount, maxCount)) { Class<?> operandClass = Boolean.class; Object o0 = ee.evaluate(e.getOperand(0)); if (!checkCompatibleOperand(o0, operandClass)) throw new IncompatibleOperandException(e, o0, operandClass); else o0 = convertCompatibleOperand(o0, operandClass); Object o1 = ee.evaluate(e.getOperand(1)); if (!checkCompatibleOperand(o1, operandClass)) throw new IncompatibleOperandException(e, o1, operandClass); else o1 = convertCompatibleOperand(o1, operandClass); return evaluate(ee.getState(), e.getOperator(), o0, o1); } else throw new BadOperandCountException(e, minCount, maxCount); } else throw new BadOperatorException(e, "binary logic"); }
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int minCount = 2; final int maxCount = 2; if (checkOperandCount(e, minCount, maxCount)) { Class<?> operandClass = Number.class; Object o0 = ee.evaluate(e.getOperand(0)); if (!checkCompatibleOperand(o0, operandClass)) throw new IncompatibleOperandException(e, o0, operandClass); else o0 = convertCompatibleOperand(o0, operandClass); Object o1 = ee.evaluate(e.getOperand(1)); if (!checkCompatibleOperand(o1, operandClass)) throw new IncompatibleOperandException(e, o1, operandClass); else o1 = convertCompatibleOperand(o1, operandClass); return evaluate(ee.getState(), e.getOperator(), o0, o1); } else throw new BadOperandCountException(e, minCount, maxCount); } else throw new BadOperatorException(e, "binary arithmetic"); }
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int minCount = 1; final int maxCount = 1; if (checkOperandCount(e, minCount, maxCount)) { Class<?> operandClass = Boolean.class; Object o0 = ee.evaluate(e.getOperand(0)); if (!checkCompatibleOperand(o0, operandClass)) throw new IncompatibleOperandException(e, o0, operandClass); else o0 = convertCompatibleOperand(o0, operandClass); return evaluate(ee.getState(), e.getOperator(), o0); } else throw new BadOperandCountException(e, minCount, maxCount); } else throw new BadOperatorException(e, "unary logic"); }
private boolean checkOperator(Expression e) { Operator operator = e.getOperator(); if (operator == Operator.EQ) return true; else if (operator == Operator.GEQ) return true; else if (operator == Operator.GT) return true; else if (operator == Operator.LEQ) return true; else if (operator == Operator.LT) return true; else if (operator == Operator.NEQ) return true; else return false; }
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int minCount = 1; final int maxCount = 1; if (checkOperandCount(e, minCount, maxCount)) { Class<?> operandClass = Number.class; Object o0 = ee.evaluate(e.getOperand(0)); if (!checkCompatibleOperand(o0, operandClass)) throw new IncompatibleOperandException(e, o0, operandClass); else o0 = convertCompatibleOperand(o0, operandClass); return evaluate(ee.getState(), e.getOperator(), o0); } else throw new BadOperandCountException(e, minCount, maxCount); } else throw new BadOperatorException(e, "unary arithmetic"); }
private boolean checkOperator(Expression e) { Operator operator = e.getOperator(); if (operator == Operator.ADD) return true; else if (operator == Operator.SUBTRACT) return true; else if (operator == Operator.MULTIPLY) return true; else if (operator == Operator.DIVIDE) return true; else if (operator == Operator.MODULO) return true; else return false; }
public Object evaluate(ExpressionEvaluator ee, Expression e) { if (checkOperator(e)) { final int count = 1; if (checkOperandCount(e, count)) { Object o0 = e.getOperand(0); if (!(o0 instanceof Token)) throw new IncompatibleOperandException(e, o0, Token.class); else return evaluate(ee.getState(), e.getOperator(), o0); } else throw new BadOperandCountException(e, count, count); } else throw new BadOperatorException(e, "literal"); }
public BadOperatorException(Expression e, String expectation) { this(e.getOperator(), expectation); } public BadOperatorException(Operator operator, String expectation) {
private boolean checkOperator(Expression e) { Operator operator = e.getOperator(); if (operator == Operator.NOT) return true; else return false; }
private boolean checkOperator(Expression e) { Operator operator = e.getOperator(); if (operator == Operator.GROUP) return true; else return false; }
private boolean checkOperator(Expression e) { Operator operator = e.getOperator(); if (operator == Operator.AND) return true; else if (operator == Operator.OR) return true; else return false; }
private boolean checkOperator(Expression e) { Operator operator = e.getOperator(); if (operator == Operator.MINUS) return true; else if (operator == Operator.PLUS) return true; else return false; }
private boolean checkOperator(Expression e) { Operator operator = e.getOperator(); if (operator == Operator.LITERAL) return true; else return false; }
private boolean checkOperator(Expression e) { Operator operator = e.getOperator(); if (operator == Operator.APPLY) return true; else return false; }