Changeset 3656


Ignore:
Timestamp:
Aug 13, 2007, 8:03:01 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #719: Add support for JEP if() function

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/util/jep/convert/ConverterFactory.java

    r3604 r3656  
    3939import org.nfunk.jep.function.Divide;
    4040import org.nfunk.jep.function.Exp;
     41import org.nfunk.jep.function.If;
    4142import org.nfunk.jep.function.Logarithm;
    4243import org.nfunk.jep.function.Multiply;
     
    9596    converters.put(Abs.class, new AbsConverter());
    9697    converters.put(Exp.class, new ExpConverter());
     98    converters.put(If.class, new IfConverter());
    9799   
    98100    // Constant values
  • trunk/src/test/TestJep.java

    r3604 r3656  
    4646    String expression1 = "raw(ch1FgMean) - raw(ch1BgMean)";
    4747    String expression2 = "ln((raw(ch1FgMean) - raw(ch1BgMean)) / (raw(ch2FgMean) - raw(ch2BgMean)))";
    48     String bigExpression = "1+sqrt(2)-exp(3)*abs(-4)/log(5)+ln(5.99)+x";
     48    String bigExpression = "1+sqrt(2)-exp(3)*abs(-4)/log(5)+ln(5.99)+x+if(a<b, 11, -11)";
    4949    String restriction1 = expression1 + " > 0";
    5050    String restriction2 = expression2 + " > 2";
  • trunk/www/common/expression_builder.jsp

    r3456 r3656  
    193193      if (frm.expression.value != '')
    194194      {
     195        var expression = frm.expression.value.replace('if(', 'jepIf(');
    195196        try
    196197        {
    197           var result = eval(frm.expression.value);
     198          var result = eval(expression);
    198199          alert('The expressions seems to be ok.\nNote! This feature is experimental and may not be 100% correct.');
    199200        }
     
    286287      return Math.random() * 100;
    287288    }
     289    function jepIf(condition, ifTrue, ifFalse)
     290    {
     291      if (condition == undefined || ifTrue == undefined || ifFalse == undefined)
     292      {
     293        throw 'if() needs 3 arguments';
     294      }
     295      return condition ? ifTrue : ifFalse;
     296    }
    288297    </script>
    289298  </base:head>
     
    303312            tooltip="BOOLEAN AND: expr1 &amp;&amp; expr2"
    304313            onclick="encloseSelection(' &amp;&amp; ', '')"
    305             visible="<%=restrictions%>"
    306314          />
    307315          <tbl:button
     
    309317            tooltip="BOOLEAN OR: expr1 || expr2"
    310318            onclick="encloseSelection(' || ', '')"
    311             visible="<%=restrictions%>"
    312319          />
    313320          <tbl:button
     
    315322            tooltip="BOOLEAN NOT: !expr1"
    316323            onclick="encloseSelection('!', '')"
    317             visible="<%=restrictions%>"
    318324          />
    319325          <tbl:button
     
    321327            tooltip="EQUAL: expr1 == expr2"
    322328            onclick="encloseSelection(' == ', '')"
    323             visible="<%=restrictions%>"
    324329          />
    325330          <tbl:button
     
    327332            tooltip="INEQUAL: expr1 != expr2"
    328333            onclick="encloseSelection(' != ', '')"
    329             visible="<%=restrictions%>"
    330334          />
    331335          <tbl:button
     
    333337            tooltip="LESS: expr1 &lt; expr2"
    334338            onclick="encloseSelection(' &lt; ', '')"
    335             visible="<%=restrictions%>"
    336339          />
    337340          <tbl:button
     
    339342            tooltip="LESS OR EQUAL: expr1 &lt;= expr2"
    340343            onclick="encloseSelection(' &lt;= ', '')"
    341             visible="<%=restrictions%>"
    342344          />
    343345          <tbl:button
     
    351353            tooltip="MORE: expr1 &gt; expr2"
    352354            onclick="encloseSelection(' &gt; ', '')"
    353             visible="<%=restrictions%>"
    354355          />
    355356          <tbl:button
Note: See TracChangeset for help on using the changeset viewer.