2.17.2: 2011-06-17

net.sf.basedb.util.jep
Class MeanFunction

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

public class MeanFunction
extends Object
implements JepExpressionFunction

A JEP function class that adds a mean(string) function to a JEP expression parser. The function will calculate the mean value of the raw data property with the given name. For example: mean('ch1BgMean')

To be able to use this function it must be registered with the JEP parser and, before the expression is evaluated, a rawbioassay object must be set. For example we can evaluate an expression for every raw data object in a raw bioassay:

DbControl dc = ...
RawBioAssay assay = ...
String expression = "raw('ch1FgMean') - mean('ch1BgMean')";
RawFunction raw = new RawFunction(assay.getRawDataType());
MeanFunction mean = new MeanFunction(assay);
JEP jep = JepUtil.newJep(expression, raw, mean);
DataResultIterator<RawData> result = 
   assay.getRawData().iterate(dc);
while (result.hasNext())
{
   raw.setRawData(result.next());
   double value = jep.getValue();
   // Do something with the value
}
result.close();

Version:
2.0
Author:
Nicklas
See Also:
Jep
Last modified
$Date: 2009-04-06 14:52:39 +0200 (Mon, 06 Apr 2009) $

Field Summary
private  DbControl dc
           
private  Map<String,Float> means
          Holds a cache of the values.
private  int numParameters
           
private  RawBioAssay rawBioAssay
           
private  RawData rawData
           
 
Constructor Summary
MeanFunction(DbControl dc)
          Create a new instance of this function working with raw data of the specified raw bio assay.
 
Method Summary
 boolean checkNumberOfParameters(int n)
           
 String getFunctionName()
          Get the name of this function.
 int getNumberOfParameters()
           
 RawData getRawData()
          Get the current raw data object used when evaluating the JEP expression.
 float mean(String propertyName)
          Get the value of the specified property of the current raw data object.
 void run(Stack stack)
           
 void setCurNumberOfParameters(int n)
           
 void setRawData(RawData rawData)
          Set a new raw data object that will be used the next time the JEP expression is evaluated.
 Expression toExpression(Node node)
          Use the Dynamic.meanRawData(String) method to create an expression for the mean of the given raw data property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

means

private final Map<String,Float> means
Holds a cache of the values.


dc

private final DbControl dc

numParameters

private int numParameters

rawBioAssay

private RawBioAssay rawBioAssay

rawData

private RawData rawData
Constructor Detail

MeanFunction

public MeanFunction(DbControl dc)
Create a new instance of this function working with raw data of the specified raw bio assay.

Parameters:
dc - DbControl used in this function
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 "mean"
See Also:
JEP.addFunction(String, PostfixMathCommandI)

toExpression

public Expression toExpression(Node node)
Use the Dynamic.meanRawData(String) method to create an expression for the mean of the given raw data property.

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

setRawData

public void setRawData(RawData rawData)
Set a new raw data object that will be used the next time the JEP expression is evaluated.

Parameters:
rawData - The raw data object to use

getRawData

public RawData getRawData()
Get the current raw data object used when evaluating the JEP expression.


mean

public float mean(String propertyName)
           throws ParseException
Get the value of the specified property of the current raw data object. This method uses Hibernate metadata to find the value.

Parameters:
propertyName - The name of the raw data property. Null is not allowed.
Returns:
The mean value as a float.
Throws:
ParseException - If the property name is null or if there is another error.

2.17.2: 2011-06-17