Package org.openntf.formula

Examples of org.openntf.formula.FormulaContext


      }
      // benchmark the evaluate with a document as context

      try {
        time = System.nanoTime();
        FormulaContext ctx1 = Formulas.createContext(ntfDoc, Formulas.getParser());
        ntfDocResult = ast.solve(ctx1);
        docEvaluateTime += System.nanoTime() - time;
      } catch (Exception e) {
        System.out.println(NTF("Doc-Evaluate failed: ") + ERROR(e));
        e.printStackTrace();
        i = count;
      }
      try {
        // benchmark the evaluate with a map as context
        time = System.nanoTime();
        FormulaContext ctx2 = Formulas.createContext(ntfMap, Formulas.getParser());
        ntfMapResult = ast.solve(ctx2);
        mapEvaluateTime += System.nanoTime() - time;
      } catch (Exception e) {
        System.out.println(NTF("Map-Evaluate failed: ") + ERROR(e));
        e.printStackTrace();
View Full Code Here


      }
      // benchmark the evaluate with a document as context

      try {
        time = System.nanoTime();
        FormulaContext ctx1 = Formulas.createContext(ntfDoc, Formulas.getParser());
        ntfDocResult = ast.solve(ctx1);
        docEvaluateTime += System.nanoTime() - time;
      } catch (Exception e) {
        System.out.println(NTF("Doc-Evaluate failed: ") + ERROR(e));
        e.printStackTrace();
        i = count;
      }
      try {
        // benchmark the evaluate with a map as context
        time = System.nanoTime();
        FormulaContext ctx2 = Formulas.createContext(ntfMap, Formulas.getParser());
        ntfMapResult = ast.solve(ctx2);
        mapEvaluateTime += System.nanoTime() - time;
      } catch (Exception e) {
        System.out.println(NTF("Map-Evaluate failed: ") + ERROR(e));
        e.printStackTrace();
View Full Code Here

    }

    if (!parserFailed) {
      if (testDoc) {
        try {
          FormulaContext ctx1 = Formulas.createContext(ntfDoc, parser);
          ntfDocResult = ast.solve(ctx1);
        } catch (EvaluateException e) {
          errors.append(NTF("\tDoc-Evaluate failed: ") + ERROR(e) + "\n");
          ntfError = e;
          parserFailed = true;
        } catch (Throwable t) {
          System.err.println(ERROR("FATAL") + NTF("\tDoc-Evaluate failed: ") + ERROR(t));
          t.printStackTrace();
        }
      }
      if (testMap) {
        try {
          // benchmark the evaluate with a map as context
          FormulaContext ctx2 = Formulas.createContext(ntfMap, parser);
          ntfMapResult = ast.solve(ctx2);
        } catch (EvaluateException e) {
          errors.append(NTF("\tMap-Evaluate failed: ") + ERROR(e) + "\n");
          ntfError = e;
          parserFailed = true;
View Full Code Here

    }

    if (!parserFailed) {
      try {
        // benchmark the evaluate with a map as context
        FormulaContext ctx2 = Formulas.createContext(ntfMap, parser);
        ntfMapResult = ast.solve(ctx2);
      } catch (EvaluateException e) {
        errors.append(NTF("\tMap-Evaluate failed: ") + ERROR(e) + "\n");
        ntfError = e;
        parserFailed = true;
View Full Code Here

        return null;
      }

    });
    ASTNode x = p.parse(System.in, true);
    FormulaContext ctx = Formulas.createContext(null, p);

    ctx.setParameterProvider(new FormulaProvider<String>() {

      public String get(final String key) {
        return args[Integer.valueOf(key)];
      }
    });
View Full Code Here

    return solve(docMap, contextMap);
  }

  /*----------------------------------------------------------------------------*/
  private String solve(final LSFocStringMap docMap, final LSFocStringMap contextMap) {
    FormulaContext ctx = Formulas.createContext(docMap, iParser);
    ctx.useBooleans(false);
    ctx.setParameterProvider(new FormulaProvider<Object>() {
      public Object get(final String what) {
        return contextMap.get(what);
      }
    });
    try {
View Full Code Here

    vhi.getBoolean(0);
  }

  @Test
  public final void testIsTrue() {
    FormulaContext ctx = Formulas.createContext(null, null);
    ctx.useBooleans(false);
    assertTrue(!vhi.isTrue(ctx));
    vhi.add(0);
    assertTrue(!vhi.isTrue(ctx));
    vhi.add(1);
    assertTrue(vhi.isTrue(ctx));
View Full Code Here

    assertTrue(vhi.isTrue(ctx));
  }

  @Test(expected = ClassCastException.class)
  public final void testIsTrue2() {
    FormulaContext ctx = Formulas.createContext(null, null);
    ctx.useBooleans(true);
    vhi.add(0);
    assertTrue(!vhi.isTrue(ctx));
  }
View Full Code Here

    try {
      String passedFormula = (String) ExtLibUtil.getViewScope().get("javaFormula");
      ASTNode ast = null;

      ast = Formulas.getParser().parse(passedFormula);
      FormulaContext ctx1 = Formulas.createContext(null, Formulas.getParser());
      List<Object> result = ast.solve(ctx1);
      ExtLibUtil.getViewScope().put("javaTest", result);
    } catch (Throwable t) {
      XspOpenLogUtil.logError(t);
    }
View Full Code Here

      System.err.println("[FormulaEngine] 10000x building AST tree\ttook " + time + "ms.");
      //n.dump("");

      time = System.currentTimeMillis();
      for (int i = 1; i < 10000; i++) {
        FormulaContext ctx = Formulas.createContext(null, parser);
        v = n.solve(ctx);
      }
      time = System.currentTimeMillis() - time;
      System.err.println("[FormulaEngine] 10000x evaluating AST tree\ttook " + time + "ms.");
View Full Code Here

TOP

Related Classes of org.openntf.formula.FormulaContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.