Package org.nfunk.jep

Examples of org.nfunk.jep.JEP


                                                              double highrange,
                                                              int amount,
                                                              String function,
                                                              String[] rows) {
        double x = 0.0;
        JEP jep = new JEP();
        jep.addStandardConstants();
        jep.addStandardFunctions();
       
        jep.parseExpression(function);
       
        String[] vars = jep.getVariables();
        String var = "x";
           
        if(vars.length > 1)
            throw new IllegalArgumentException("The supplied function contains more than one variable.");
       
        if(vars.length == 1)
            var = vars[0];
       
        double[][] model = new double[1][amount];
        double[] columns = new double[amount];
                       
        for(int i = 1; i <= amount; i++) {
            x = lowrange + i * ((double)Math.abs(highrange - lowrange) / amount);
            columns[i-1] = x;
            jep.addVariable(var, x);
            model[0][i-1] = jep.getValue();           
            //System.out.println("** Calc("+columns[i-1]+") = "+model[0][i-1]);
        }
               
        return new DefaultChartDataModel(model, columns, rows);
    }
View Full Code Here


public class JEPWrapper {
  private final JEP parser;

  public JEPWrapper() {
    parser = new JEP();
    parser.addStandardConstants();
    parser.addStandardFunctions();
    parser.addFunction("rect", new Rect());
    parser.addFunction("sawtooth", new Sawtooth());
    parser.addFunction("triangle", new Triangle());
View Full Code Here

   * @param attributes
   * @return resultat
   */
  public static Double calculate(final String formula,
      final Collection<OrderLineAttribute> attributes) {
    JEP jep = getJEP(formula);

    addAttributesToFormula(attributes, jep);
    return jep.getValue();
  }
View Full Code Here

      }
    }
  }

  private static JEP getJEP(final String formula) {
    JEP jep = new JEP();
    jep.addStandardFunctions();
    jep.addStandardConstants();
    jep.setAllowUndeclared(true);
    jep.setImplicitMul(true);
    jep.parseExpression(formula);
    return jep;
  }
View Full Code Here

    public double expandFieldValue(int index, BigInteger bits) {       
        FieldDefinition fd = getField(index);
        BigInteger raw = extractFieldValue(fd.getName(), bits);
        String expression = fd.getOperands();
        JEP expressionParser = new JEP();
       
       
        if PropertiesUtil.isEmpty(expression) ) {
            return raw.doubleValue();
        }
      
       
        if (expression.indexOf('[') != -1 ) {
            // this is a look up expresion
            double []vals = parseLookupTable(expression);
           
            return vals[raw.intValue()];       
        }
       
        List ids = parseIdentifiers(expression);
       
        if ( ids.size() != 0 ) {
            expression = removeIdentifiers(expression);
           
            Iterator tor = ids.iterator();
            while (tor.hasNext()) {
                String idName = (String) tor.next();
                FieldDefinition fieldDefinition = (FieldDefinition) getField(idName);
               
                if ( fieldDefinition == null ) {
                    throw new IllegalArgumentException("unknown field: " + idName);
                }
               
                if ( fieldDefinition.getOffset() < fd.getOffset() ) {
                    throw new IllegalStateException("cannot access downstream field: " + idName);
                }
               
                expressionParser.addVariable(idName, expandFieldValue(fieldDefinition.getIndex(), bits));               
            }
        }
       
        expressionParser.addVariable("x", raw.floatValue());
        expressionParser.addVariable("fieldWidth", fd.getWidth());
        expressionParser.addVariable("maxValue", EncodingUtil.getMaxValue(fd.getWidth()).floatValue());
        expressionParser.parseExpression(expression);
       
        
        return expressionParser.getValue();       
    }
View Full Code Here

    public ParserExpressao(List<String> var) {

        int i;
       
        j = new JEP();
       
        for (i=0;i<var.size();i++)
            j.addConstant(var.get(i), (Object) 0);

        j.addConstant("ß0", (Object) 0);
View Full Code Here

    public ParserEquacao(List<String> var) {

        int i;
       
        j = new JEP();
       
        for (i=0;i<var.size();i++)
            j.addConstant(var.get(i), (Object) 0);

        j.addConstant("ß0", (Object) 0);
View Full Code Here

        // set gradient
        gjep = new JEP[super.variables.length];
        for (int i=0; i<super.variables.length; i++)
        {
            gjep[i] = new JEP();
            gjep[i].addStandardFunctions();
            gjep[i].addStandardConstants();
            for (String var:super.variables)
                gjep[i].addVariable(var, 0);
            gjep[i].parseExpression(_derivatives[i]);
View Full Code Here

  private JEP evaluator;
  private List<Function> functions;
  private List<Operator> operators;

  public EvaluatorFacade() {
    evaluator = new JEP();
    evaluator.addStandardConstants();
    evaluator.addStandardFunctions();
   
    collectOperators();
    collectFunctions();
View Full Code Here

TOP

Related Classes of org.nfunk.jep.JEP

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.