Package net.sf.basedb.util.jep
Class RawFunction
java.lang.Object
net.sf.basedb.util.jep.RawFunction
- All Implemented Interfaces:
JepExpressionFunction
,JepFunction
,org.nfunk.jep.function.PostfixMathCommandI
A JEP function class that adds a
raw(string)
function to a
JEP expression parser. The function will look up the value of the raw data
property with the given name. For example:
raw('ch1FgMean') - raw('ch1BgMean')
To be able to use this function it must be registered with the JEP parser and, before the expression is evaluated, a raw data 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') - raw('ch1BgMean')"; RawFunction raw = new RawFunction(assay.getRawDataType()); JEP jep = JepUtil.newJep(expression, raw); 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:
- Last modified
- $Date: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate final boolean
private final DbControl
private int
private RawData
private final RawDataType
-
Constructor Summary
ConstructorDescriptionRawFunction
(boolean allowUse) Create a new instance of this function.RawFunction
(DbControl dc, RawDataType rawDataType, boolean allowUse) Create a new instance of this function working with raw data of the specified raw data type. -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkNumberOfParameters
(int n) Get the name of this function.int
Get the current raw data object used when evaluating the JEP expression.Get the raw data type this function uses.Get the value of the specified property of the current raw data object.void
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.toExpression
(Node node) Use theDynamic.rawData(String)
method to create an expression referencing a raw data property.
-
Field Details
-
rawDataType
-
metaData
-
dc
-
allowUse
private final boolean allowUse -
numParameters
private int numParameters -
rawData
-
-
Constructor Details
-
RawFunction
public RawFunction(boolean allowUse) 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 toExpression
:s. -
RawFunction
Create a new instance of this function working with raw data of the specified raw data type.- Parameters:
rawDataType
- The type of raw data this function uses
-
-
Method Details
-
getFunctionName
Description copied from interface:JepFunction
Get the name of this function. It is used when registering the function with aJEP
parser.- Specified by:
getFunctionName
in interfaceJepFunction
- Returns:
- The string "raw"
- See Also:
-
toExpression
Use theDynamic.rawData(String)
method to create an expression referencing a raw data property.- Specified by:
toExpression
in interfaceJepExpressionFunction
- Parameters:
node
- The node representing this function- Returns:
- An
Expression
object
-
getNumberOfParameters
public int getNumberOfParameters()- Specified by:
getNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
- Returns:
- Always 1
-
setCurNumberOfParameters
public void setCurNumberOfParameters(int n) - Specified by:
setCurNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
-
checkNumberOfParameters
public boolean checkNumberOfParameters(int n) - Specified by:
checkNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
-
run
- Specified by:
run
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
- Throws:
ParseException
-
getRawDataType
Get the raw data type this function uses. -
setRawData
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
Get the current raw data object used when evaluating the JEP expression. -
raw
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 value as a java.lang.Object
- Throws:
ParseException
- If required arguments is null
-