Exemplo n.º 1
0
 public boolean evaluateFunctionLogical(final FunctionNode functionNode) {
   if (functionNode.size() > 0 && functionNode.getNode(0) instanceof SymbolNode) {
     String symbol = functionNode.getNode(0).toString();
     if (functionNode.size() == 2) {
       IBooleanFunction<T> function = getFunctionBooleanMap(symbol);
       if (function instanceof IBooleanBoolean1Function) {
         return ((IBooleanBoolean1Function) function)
             .evaluate(evaluateNodeLogical(functionNode.getNode(1)));
       }
     } else if (functionNode.size() == 3) {
       IBooleanFunction<T> function = getFunctionBooleanMap(symbol);
       if (function instanceof IBooleanFieldElement2Function) {
         return ((IBooleanFieldElement2Function<T>) function)
             .evaluate(
                 evaluateNode(functionNode.getNode(1)), evaluateNode(functionNode.getNode(2)));
       } else if (function instanceof IBooleanBoolean2Function) {
         return ((IBooleanBoolean2Function) function)
             .evaluate(
                 evaluateNodeLogical(functionNode.getNode(1)),
                 evaluateNodeLogical(functionNode.getNode(2)));
       }
       // } else {
       // Object obj = FUNCTION_BOOLEAN_MAP.get(symbol);
       // if (obj instanceof IBooleanDoubleFunction) {
       // return ((IBooleanDoubleFunction) obj).evaluate(this,
       // functionNode);
       // }
     }
   }
   throw new ArithmeticMathException(
       "AbstractASTVisitor#evaluateFunctionLogical(FunctionNode) not possible for: "
           + functionNode.toString());
 }
Exemplo n.º 2
0
 @Override
 public T visit(FunctionNode functionNode) {
   if (functionNode.size() > 0 && functionNode.getNode(0) instanceof SymbolNode) {
     String symbol = functionNode.getNode(0).toString();
     if (symbol.equals("If") || (fRelaxedSyntax && symbol.equalsIgnoreCase("If"))) {
       if (functionNode.size() == 3) {
         if (evaluateNodeLogical(functionNode.getNode(1))) {
           return evaluateNode(functionNode.getNode(2));
         }
       } else if (functionNode.size() == 4) {
         if (evaluateNodeLogical(functionNode.getNode(1))) {
           return evaluateNode(functionNode.getNode(2));
         } else {
           return evaluateNode(functionNode.getNode(3));
         }
       }
     } else {
       IFieldElementFunction<T> function = getFunctionMap(symbol);
       if (function instanceof IFieldElementFunctionNode) {
         return ((IFieldElementFunctionNode<T>) function).evaluate(this, functionNode);
       }
       if (functionNode.size() == 1) {
         if (function instanceof IFieldElement0Function) {
           return ((IFieldElement0Function<T>) function).evaluate();
         }
       } else if (functionNode.size() == 2) {
         if (function instanceof IFieldElement1Function) {
           return ((IFieldElement1Function<T>) function)
               .evaluate(evaluateNode(functionNode.getNode(1)));
         }
       } else if (functionNode.size() == 3) {
         ASTNode arg2 = functionNode.getNode(2);
         if (function instanceof IFieldElementInt2Function && arg2 instanceof IntegerNode) {
           return ((IFieldElementInt2Function<T>) function)
               .evaluate(
                   evaluateNode(functionNode.getNode(1)), ((IntegerNode) arg2).getIntValue());
         }
         if (function instanceof IFieldElement2Function) {
           return ((IFieldElement2Function<T>) function)
               .evaluate(
                   evaluateNode(functionNode.getNode(1)), evaluateNode(functionNode.getNode(2)));
         }
       }
     }
   }
   throw new ArithmeticMathException(
       "AbstractASTVisitor#evaluateFunction(FunctionNode) not possible for: "
           + functionNode.toString());
 }