public abstract class JELRowReader
extends gnu.jel.DVMap
evaluate(gnu.jel.CompiledExpression)
method.
This class currently deals with columns of all the primitive types,
objects of type String
or Date
,
and arrays of any of these.
Anything else is treated as an Object
or Object[]
.
It could be extended to deal with more if necessary.
Expressions of the following types are understood:
null
value (this is not provided as part of the JEL
engine).
null
. This has the same effect as throwing a
NullPointerException
during evaluation.
The NULL token is syntactically of type byte
, which can
be promoted implicitly to any numeric value; this means it can be
used anywhere a primitive (other than boolean
) can be used.
true
iff the corresponding
value (at the current row, if applicable) has a blank value.
Object
.
This can be useful for passing to functions that need to know
whether a null value is present (which cannot be represented
in primitive types).
Modifier and Type | Field and Description |
---|---|
static char |
COLUMN_ID_CHAR
Prefix identifying a unique column identifier.
|
static String |
NULL_QUERY_PREFIX
The string which, when prefixed to a column identifier, indicates
that the null-ness of the column should be queried.
|
static String |
OBJECT_PREFIX
The string which, when prefixed to a column identifier, indicates
that the value is required as an Object not a primitive.
|
Constructor and Description |
---|
JELRowReader()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
Object |
evaluate(gnu.jel.CompiledExpression compEx)
Evaluates a given compiled expression at the current row.
|
boolean |
evaluateBoolean(gnu.jel.CompiledExpression compEx)
Evaluates a given compiled expression at the current row under the
assumption that the expression represents a boolean value.
|
double |
evaluateDouble(gnu.jel.CompiledExpression compEx)
Evaluates a given compiled expression at the current row under the
assumption that the expression represents a numeric value.
|
protected void |
foundNull()
Must be called by any of the
getObjectColumnValue methods
which wants to return a null but has to return a
primitive instead. |
boolean[] |
getBooleanArrayProperty(int id) |
protected abstract boolean |
getBooleanColumnValue(int icol)
Returns a boolean value for a cell of the current row.
|
boolean |
getBooleanProperty(int id) |
boolean |
getBooleanProperty(long inul)
Indicates whether the cell at the current row in a given column
has a blank value.
|
boolean |
getBooleanValue(Boolean value) |
byte[] |
getByteArrayProperty(int id) |
protected abstract byte |
getByteColumnValue(int icol)
Returns a byte value for a cell of the current row.
|
byte |
getByteProperty(int id) |
byte |
getByteValue(Byte value) |
char[] |
getCharArrayProperty(int id) |
protected abstract char |
getCharColumnValue(int icol)
Returns a char value for a cell of the current row.
|
char |
getCharProperty(int id) |
char |
getCharValue(Character value) |
protected abstract Class<?> |
getColumnClass(int icol)
Returns the class of values returned by a given column.
|
int |
getColumnIndex(String name)
Returns the column index in the table model which corresponds to
a given name.
|
protected abstract int |
getColumnIndexByName(String name)
Returns the column index of a column in the row given its name.
|
protected abstract Constant<?> |
getConstantByName(String name)
Returns a constant value for this reader given its name.
|
Date[] |
getDateArrayProperty(int id) |
double[] |
getDoubleArrayProperty(int id) |
protected abstract double |
getDoubleColumnValue(int icol)
Returns a double value for a cell of the current row.
|
double |
getDoubleProperty(int id) |
double |
getDoubleValue(Double value) |
float[] |
getFloatArrayProperty(int id) |
protected abstract float |
getFloatColumnValue(int icol)
Returns a float value for a cell of the current row.
|
float |
getFloatProperty(int id) |
float |
getFloatValue(Float value) |
int[] |
getIntArrayProperty(int id) |
protected abstract int |
getIntColumnValue(int icol)
Returns a int value for a cell of the current row.
|
int |
getIntProperty(int id) |
int |
getIntValue(Integer value) |
long[] |
getLongArrayProperty(int id) |
protected abstract long |
getLongColumnValue(int icol)
Returns a long value for a cell of the current row.
|
long |
getLongProperty(int id) |
long |
getLongValue(Long value) |
Number |
getNumberProperty(int id) |
Object[] |
getObjectArrayProperty(int id) |
protected abstract Object |
getObjectColumnValue(int icol)
Returns an Object value for a cell of the current row.
|
Object |
getObjectProperty(int id) |
short[] |
getShortArrayProperty(int id) |
protected abstract short |
getShortColumnValue(int icol)
Returns a short value for a cell of the current row.
|
short |
getShortProperty(int id) |
short |
getShortValue(Short value) |
protected Constant<?> |
getSpecialByName(String name)
Returns the a special quantity which corresponds to
a given name, or null if it isn't a special.
|
String[] |
getStringArrayProperty(int id) |
String |
getStringProperty(int id) |
int[] |
getTranslatedColumns()
Returns a set (no duplicated elements) of the column indices
for which this RowReader has been asked to provide translation values.
|
Constant<?>[] |
getTranslatedConstants()
Returns a list of the constants for which this RowReader has
been asked to provide translation values.
|
String |
getTypeName(String name)
Returns the type name of the quantity which is referenced in
expressions with a given name.
|
protected abstract boolean |
isBlank(int icol)
Indicates whether the value in a given column is null.
|
void |
setFailOnNull(boolean failOnNull)
Configures the behaviour when a primitive integer or boolean
value passed as an argument to a function for evaluation
is represented by a null value in the column.
|
static String |
stripPrefix(String name,
String prefix)
Takes a token and strips a given prefix from it, returning the
remainder.
|
Object |
translate(String name)
Turns a value specification into a constant object which can be
used at evaluation time to reference a particular quantity to
evaluate.
|
public static final String NULL_QUERY_PREFIX
public static final String OBJECT_PREFIX
public static final char COLUMN_ID_CHAR
public void setFailOnNull(boolean failOnNull)
The default behaviour is false.
failOnNull
- failOnNull flagprotected abstract int getColumnIndexByName(String name)
name
does not refer to any known column, return -1.name
- column nameprotected abstract Constant<?> getConstantByName(String name)
name
- constant nameprotected abstract boolean isBlank(int icol)
icol
- column indexprotected abstract Class<?> getColumnClass(int icol)
icol
- non-negative column indexprotected abstract boolean getBooleanColumnValue(int icol)
foundNull()
(and return any value) if the result
is null.icol
- column indexprotected abstract byte getByteColumnValue(int icol)
foundNull()
(and return any value) if the result
is null.icol
- column indexprotected abstract char getCharColumnValue(int icol)
foundNull()
(and return any value) if the result
is null.icol
- column indexprotected abstract short getShortColumnValue(int icol)
foundNull()
(and return any value) if the result
is null.icol
- column indexprotected abstract int getIntColumnValue(int icol)
foundNull()
(and return any value) if the result
is null.icol
- column indexprotected abstract long getLongColumnValue(int icol)
foundNull()
(and return any value) if the result
is null.icol
- column indexprotected abstract float getFloatColumnValue(int icol)
foundNull()
(and return any value) if the result
is null.icol
- column indexprotected abstract double getDoubleColumnValue(int icol)
foundNull()
(and return any value) if the result
is null.icol
- column indexprotected abstract Object getObjectColumnValue(int icol)
icol
- column indexprotected void foundNull()
getObjectColumnValue
methods
which wants to return a null
but has to return a
primitive instead.protected Constant<?> getSpecialByName(String name)
The current specials are:
null
value (this is not built in
to the JEL evaluator)
name
- special namepublic Object evaluate(gnu.jel.CompiledExpression compEx) throws Throwable
compEx
- compiled expressionThrowable
public boolean evaluateBoolean(gnu.jel.CompiledExpression compEx) throws Throwable
compEx
- numeric-valued compiled expressionThrowable
public double evaluateDouble(gnu.jel.CompiledExpression compEx) throws Throwable
compEx
- numeric-valued compiled expressionThrowable
public String getTypeName(String name)
getXXXProperty
methods in this class.getTypeName
in class gnu.jel.DVMap
name
- the variable namepublic Object translate(String name)
Integer
object (the column index) if
name
appears to reference a known column
Integer
object (-1-constIndex) if
name
appears to reference a known constant
Long
object if it is a null query on a known column
null
otherwise
This method is only called at expression compilation time, not evaluation time, so it doesn't need to be particularly fast.
translate
in class gnu.jel.DVMap
name
- the name of the variable-like object to evaluatepublic Constant<?>[] getTranslatedConstants()
public int[] getTranslatedColumns()
public final int getColumnIndex(String name)
Note this method is only called during expression compilation, so it doesn't need to be particularly efficient.
name
- column identifierpublic boolean getBooleanProperty(long inul)
null
reference, or if it is a Float or Double
with a NaN value.inul
- column index (as a long
)public boolean getBooleanProperty(int id)
public byte getByteProperty(int id)
public char getCharProperty(int id)
public short getShortProperty(int id)
public int getIntProperty(int id)
public long getLongProperty(int id)
public float getFloatProperty(int id)
public double getDoubleProperty(int id)
public Object getObjectProperty(int id)
public Number getNumberProperty(int id)
public String getStringProperty(int id)
public boolean[] getBooleanArrayProperty(int id)
public byte[] getByteArrayProperty(int id)
public char[] getCharArrayProperty(int id)
public short[] getShortArrayProperty(int id)
public int[] getIntArrayProperty(int id)
public long[] getLongArrayProperty(int id)
public float[] getFloatArrayProperty(int id)
public double[] getDoubleArrayProperty(int id)
public Object[] getObjectArrayProperty(int id)
public String[] getStringArrayProperty(int id)
public Date[] getDateArrayProperty(int id)
public boolean getBooleanValue(Boolean value)
public byte getByteValue(Byte value)
public char getCharValue(Character value)
public short getShortValue(Short value)
public int getIntValue(Integer value)
public long getLongValue(Long value)
public float getFloatValue(Float value)
public double getDoubleValue(Double value)
public static String stripPrefix(String name, String prefix)
name
does not begin with
prefix
(or if it is exactly equal to it),
then null
is returned.name
- token which may begin with prefix
prefix
- maybe matches the start of name
name
minux prefix
,
or null
NULL_QUERY_PREFIX
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.