2.17.2: 2011-06-17

net.sf.basedb.util.jep
Class ScoreFunction

java.lang.Object
  extended by net.sf.basedb.util.jep.ScoreFunction
All Implemented Interfaces:
JepExpressionFunction, JepFunction, org.nfunk.jep.function.PostfixMathCommandI

public class ScoreFunction
extends Object
implements JepExpressionFunction

A JEP function class that adds a score(reporterListId) function to a JEP expression parser. The function will look up a reporters score in the reporter list with the ID given as an argument to this function.

To be able to use this function it must be registered with the JEP parser and, before the expression is evaluated, a SqlResult object must be set.

Version:
2.0
Author:
Nicklas
See Also:
Jep, BioAssaySetUtil.createJepExpression(DbControl, String, DynamicQuery)
Last modified
$Date: 2010-04-20 10:02:16 +0200 (Tue, 20 Apr 2010) $

Field Summary
private  DbControl dc
           
private  int numParameters
           
private  SqlResult result
           
private  int scoreIndex
           
 
Constructor Summary
ScoreFunction(DbControl dc)
          Create a new instance of this function.
ScoreFunction(DbControl dc, int scoreIndex)
          Create a new instance of this function which can be used to dynamically evaluate expressions.
 
Method Summary
 boolean checkNumberOfParameters(int n)
           
 String getFunctionName()
          Get the name of this function.
 int getNumberOfParameters()
           
 void run(Stack stack)
           
 Object score()
          Get the score value from the current sql result.
 void setCurNumberOfParameters(int n)
           
 void setSqlResult(SqlResult result)
          Set a new SqlResult object that will be used the next time the JEP expression is evaluated.
 Expression toExpression(Node node)
          Use the Dynamic.score(ReporterList) method to create an expression referencing the score of a reporter in the reporter list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dc

private DbControl dc

scoreIndex

private int scoreIndex

result

private SqlResult result

numParameters

private int numParameters
Constructor Detail

ScoreFunction

public ScoreFunction(DbControl dc)
Create a new instance of this function. The new instance cannot be used to dynamically evaluate expressions. It should only be used for converting JEP formulas to Expression:s.

Parameters:
dc - DbControl to use when this ScoreFunction accessing the database.
See Also:
Jep.formulaToExpression(String, JepFunction[])

ScoreFunction

public ScoreFunction(DbControl dc,
                     int scoreIndex)
Create a new instance of this function which can be used to dynamically evaluate expressions.

Parameters:
dc - DbControl to use when this ScoreFunction accessing the database.
scoreIndex - The column index in the SqlResult that holds the score value
See Also:
setSqlResult(SqlResult)
Method Detail

getFunctionName

public String getFunctionName()
Description copied from interface: JepFunction
Get the name of this function. It is used when registering the function with a JEP parser.

Specified by:
getFunctionName in interface JepFunction
Returns:
The string "score"
See Also:
JEP.addFunction(String, PostfixMathCommandI)

toExpression

public Expression toExpression(Node node)
Use the Dynamic.score(ReporterList) method to create an expression referencing the score of a reporter in the reporter list.

Specified by:
toExpression in interface JepExpressionFunction
Parameters:
node - The node representing this function
Returns:
An Expression object

getNumberOfParameters

public int getNumberOfParameters()
Specified by:
getNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI
Returns:
Always 1

setCurNumberOfParameters

public void setCurNumberOfParameters(int n)
Specified by:
setCurNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI

checkNumberOfParameters

public boolean checkNumberOfParameters(int n)
Specified by:
checkNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI

run

public void run(Stack stack)
         throws ParseException
Specified by:
run in interface org.nfunk.jep.function.PostfixMathCommandI
Throws:
ParseException

setSqlResult

public void setSqlResult(SqlResult result)
Set a new SqlResult object that will be used the next time the JEP expression is evaluated.

Parameters:
result - The result object

score

public Object score()
             throws ParseException
Get the score value from the current sql result.

Returns:
a Object
Throws:
ParseException - If no result has been specified or if getting the score result fails.

2.17.2: 2011-06-17