uk.ac.starlink.ttools
Class JELRowReader

java.lang.Object
  |
  +--gnu.jel.DVMap
        |
        +--uk.ac.starlink.ttools.JELRowReader
All Implemented Interfaces:
gnu.jel.DVResolver
Direct Known Subclasses:
DummyJELRowReader, RandomJELRowReader, SequentialJELRowReader

public abstract class JELRowReader
extends gnu.jel.DVMap

An object which is able to read cell values by column name or number. The values are got using the 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":
the null value (this is not provided as part of the JEL engine).
"NULL":
if this expression is evaluated at any point in the expression evaluation, then the result of the whole evaluation will be 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.
"$0" or "Index" (case insensitive):
the 1-based index of the current row
Column $ID identifiers:
The letter '$' followed by the 1-based index of the column refers to the contents of that column in the current row (as a primitive, if applicable).
Column names:
The name of a column (case-insensitive) refers to the contents of that column in the current row (as a primitive, if applicable) - this can only work if the column name is a legal java identifier.
Column null-queries:
The string NULL_QUERY_PREFIX followed by a column name or $ID identifier (see above) returns a boolean value which is true iff the value in that column at the current row is the null value.


Field Summary
static char COLUMN_ID_CHAR
          Prefix identifying a unique column identifier.
static String NULL_QUERY_PREFIX
          The string which, when prefixed to a column ideentifier, indicates that the null-ness of the column should be queried.
 
Constructor Summary
JELRowReader(StarTable table)
          Constructs a new row reader for a given StarTable.
 
Method Summary
 Object evaluate(gnu.jel.CompiledExpression compEx)
          Evaluates a given compiled expression at the current row.
 boolean[] getBooleanArrayProperty(int icol)
           
 boolean getBooleanProperty(int icol)
           
 boolean getBooleanProperty(long inul)
          Indicates whether the cell at the current row in a given column has a blank value.
 byte[] getByteArrayProperty(int icol)
           
 byte getByteProperty(byte ispecial)
          Returns the values for byte-typed special variables.
 byte getByteProperty(int icol)
           
protected abstract  Object getCell(int icol)
          Returns the value for a given column in this reader's table at the current row.
 char[] getCharArrayProperty(int icol)
           
 char getCharProperty(int icol)
           
abstract  long getCurrentRow()
          Returns the index of the row on which evaluations are currently taking place.
 Date[] getDateArrayProperty(int icol)
           
 Date getDateProperty(int icol)
           
 double[] getDoubleArrayProperty(int icol)
           
 double getDoubleProperty(int icol)
           
 float[] getFloatArrayProperty(int icol)
           
 float getFloatProperty(int icol)
           
 int[] getIntArrayProperty(int icol)
           
 int getIntProperty(int icol)
           
 long[] getLongArrayProperty(int icol)
           
 long getLongProperty(byte ispecial)
          Returns the values for long-typed special variables.
 long getLongProperty(int icol)
           
 Object[] getObjectArrayProperty(int icol)
           
 Object getObjectProperty(byte ispecial)
          Returns the values for Object-typed special variables.
 Object getObjectProperty(int icol)
           
 short[] getShortArrayProperty(int icol)
           
 short getShortProperty(int icol)
           
 String[] getStringArrayProperty(int icol)
           
 String getStringProperty(int icol)
           
 String getTypeName(String name)
          Returns the type name of the quantity which is referenced in expressions with a given name.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_QUERY_PREFIX

public static final String NULL_QUERY_PREFIX
The string which, when prefixed to a column ideentifier, indicates that the null-ness of the column should be queried.

See Also:
Constant Field Values

COLUMN_ID_CHAR

public static final char COLUMN_ID_CHAR
Prefix identifying a unique column identifier.

See Also:
Constant Field Values
Constructor Detail

JELRowReader

public JELRowReader(StarTable table)
Constructs a new row reader for a given StarTable. Note that this reader cannot become aware of changes to the columns of the table; in the event of such changes this object should be dicarded and and a new one used for any new expressions.

Parameters:
table - the StarTable this reader will read from
Method Detail

getCell

protected abstract Object getCell(int icol)
                           throws IOException
Returns the value for a given column in this reader's table at the current row.

Parameters:
icol - column index
Returns:
contents of column icol at the current row
IOException

getCurrentRow

public abstract long getCurrentRow()
Returns the index of the row on which evaluations are currently taking place.

Returns:
row index (first row is 0)

evaluate

public Object evaluate(gnu.jel.CompiledExpression compEx)
                throws Throwable
Evaluates a given compiled expression at the current row. The returned value is wrapped up as an object if the result of the expression is a primitive.

Parameters:
compEx - compiled expression
Throwable

getTypeName

public String getTypeName(String name)
Returns the type name of the quantity which is referenced in expressions with a given name. The significance of this return value is that it appears in the names of the corresponding getXXXProperty methods in this class.

Specified by:
getTypeName in interface gnu.jel.DVResolver
Specified by:
getTypeName in class gnu.jel.DVMap
Parameters:
name - the variable name
Returns:
the corresponding method name fragment
See Also:
"JEL manual"

translate

public 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. Currently this routine returns The different integral types are only used to separate the namespaces, there is no other significance in these types.

This method is only called at expression compilation time, not evaluation time, so it doesn't need to be particularly fast.

Overrides:
translate in class gnu.jel.DVMap
Parameters:
name - the name of the variable-like object to evaluate
Returns:
a numeric object corresponding to an object which we know how to evaluate
See Also:
"JEL manual"

getLongProperty

public long getLongProperty(byte ispecial)
Returns the values for long-typed special variables.

Parameters:
ispecial - the identifier for the special
Returns:
the special's value

getObjectProperty

public Object getObjectProperty(byte ispecial)
Returns the values for Object-typed special variables.

Parameters:
ispecial - the identifier for the special
Returns:
the special's value

getByteProperty

public byte getByteProperty(byte ispecial)
Returns the values for byte-typed special variables.

Parameters:
ispecial - the identifier for the special
Returns:
the special's value

getBooleanProperty

public boolean getBooleanProperty(long inul)
Indicates whether the cell at the current row in a given column has a blank value. This is the case if the value is the java null reference, or if it is a Float or Double with a NaN value.

Parameters:
inul - column index (as a long)
Returns:
whether the cell is null

getBooleanProperty

public boolean getBooleanProperty(int icol)

getBooleanArrayProperty

public boolean[] getBooleanArrayProperty(int icol)

getByteProperty

public byte getByteProperty(int icol)

getByteArrayProperty

public byte[] getByteArrayProperty(int icol)

getCharProperty

public char getCharProperty(int icol)

getCharArrayProperty

public char[] getCharArrayProperty(int icol)

getShortProperty

public short getShortProperty(int icol)

getShortArrayProperty

public short[] getShortArrayProperty(int icol)

getIntProperty

public int getIntProperty(int icol)

getIntArrayProperty

public int[] getIntArrayProperty(int icol)

getLongProperty

public long getLongProperty(int icol)

getLongArrayProperty

public long[] getLongArrayProperty(int icol)

getFloatProperty

public float getFloatProperty(int icol)

getFloatArrayProperty

public float[] getFloatArrayProperty(int icol)

getDoubleProperty

public double getDoubleProperty(int icol)

getDoubleArrayProperty

public double[] getDoubleArrayProperty(int icol)

getStringProperty

public String getStringProperty(int icol)

getStringArrayProperty

public String[] getStringArrayProperty(int icol)

getDateProperty

public Date getDateProperty(int icol)

getDateArrayProperty

public Date[] getDateArrayProperty(int icol)

getObjectProperty

public Object getObjectProperty(int icol)

getObjectArrayProperty

public Object[] getObjectArrayProperty(int icol)

Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.