public class JELUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
CLASSES_PROPERTY
System property name for adding colon-separated list of
additional classnames containing static methods.
|
Constructor and Description |
---|
JELUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
checkExpressionType(gnu.jel.Library lib,
StarTable table,
String expr,
Class<?> clazz)
Checks that an expression is legal and returns a particular class.
|
static gnu.jel.CompiledExpression |
compile(gnu.jel.Library lib,
StarTable table,
String expr)
Compiles an expression in the context of a given table.
|
static gnu.jel.CompiledExpression |
compile(gnu.jel.Library lib,
StarTable table,
String expr,
Class<?> clazz)
Compiles an expression in the context of a given table with a
required type for the result.
|
static gnu.jel.CompiledExpression[] |
compileExpressions(StarTableJELRowReader reader,
String[] exprs)
Compiles a set of expressions relating to a table.
|
static JELQuantity |
compileQuantity(gnu.jel.Library lib,
StarTableJELRowReader jelRdr,
String expr,
Class<?> clazz)
Compiles an expression in the context of a table reader to give
a JELQuantity.
|
static java.util.function.Function<gnu.jel.Library,gnu.jel.CompiledExpression> |
compiler(StarTable table,
String expr,
Class<?> clazz)
Returns a function that can compile a fixed expression from a Library.
|
static JELRowReader |
createDatalessRowReader(StarTable table)
Returns a row reader that can be used for expression evaluation,
optionally in the context of the non-data parts of a given context
table.
|
static gnu.jel.Library |
createLibrary(Class<?>[] staticLib,
Class<?>[] dynamicLib,
gnu.jel.DVMap resolver)
Creates a JEL Library from basic information.
|
static Class<?> |
getExpressionType(gnu.jel.Library lib,
StarTable table,
String expr)
Gives the return type of an expression.
|
static gnu.jel.Library |
getLibrary(JELRowReader reader)
Returns a JEL Library suitable for expression evaluation within a table.
|
static List<Class<?>> |
getStaticClasses()
Returns the list of classes whose static methods will be mapped
into the JEL evaluation namespace.
|
static Class<?> |
getWrapperType(Class<?> clazz)
Returns a non-primitive version of a given class.
|
static IOException |
toIOException(gnu.jel.CompilationException e,
String expr)
Utility method to convert a CompilationException into an IOException.
|
public static final String CLASSES_PROPERTY
public static gnu.jel.Library getLibrary(JELRowReader reader)
reader
- object which can read rows from the table to
be used for expression evaluation; may be null if
there are no references to table-related expressionspublic static gnu.jel.Library createLibrary(Class<?>[] staticLib, Class<?>[] dynamicLib, gnu.jel.DVMap resolver)
StateDependent
annotation appropriately.staticLib
- array of classes whose public static methods
are exporteddynamicLib
- array of classes whose public methods are exportedresolver
- object used to resolve namesLibrary.Library(java.lang.Class<?>[], java.lang.Class<?>[], java.lang.Class<?>[], gnu.jel.DVMap, java.util.HashMap<java.lang.String, java.lang.Class<?>>)
public static JELRowReader createDatalessRowReader(StarTable table)
table
- context table, or nullpublic static List<Class<?>> getStaticClasses()
public static Class<?> getExpressionType(gnu.jel.Library lib, StarTable table, String expr) throws gnu.jel.CompilationException
lib
- JEL librarytable
- context tableexpr
- string representation of the expressionexpr
using lib
will returngnu.jel.CompilationException
- if expr
cannot be compiledpublic static void checkExpressionType(gnu.jel.Library lib, StarTable table, String expr, Class<?> clazz) throws gnu.jel.CompilationException
lib
- JEL librarytable
- context tableexpr
- string representation of the expressionclazz
- return type required from expr
gnu.jel.CompilationException
- if expr
cannot be compiled
or will return a type other than clazz
(or one of its subtypes)public static gnu.jel.CompiledExpression compile(gnu.jel.Library lib, StarTable table, String expr, Class<?> clazz) throws gnu.jel.CompilationException
lib
- JEL librarytable
- context tableexpr
- expression stringclazz
- required class of resulting expressiongnu.jel.CompilationException
public static gnu.jel.CompiledExpression compile(gnu.jel.Library lib, StarTable table, String expr) throws gnu.jel.CompilationException
lib
- JEL librarytable
- context tableexpr
- expression stringgnu.jel.CompilationException
public static JELQuantity compileQuantity(gnu.jel.Library lib, StarTableJELRowReader jelRdr, String expr, Class<?> clazz) throws gnu.jel.CompilationException
compile
methods, but it provides additional metadata if it can be retrieved
from the table context.lib
- JEL libraryjelRdr
- context table readerexpr
- expression stringclazz
- required return type of compiled expression,
or null if no requirementgnu.jel.CompilationException
public static java.util.function.Function<gnu.jel.Library,gnu.jel.CompiledExpression> compiler(StarTable table, String expr, Class<?> clazz) throws gnu.jel.CompilationException
table
ought not to. The returned function therefore does not need to
declare throwing a CompilerException. If for some reason the
deferred compilations do fail, a RuntimeException is returned.table
- table from which libraries will be derivedexpr
- expression to compileclazz
- required result type of expression, or null for automaticgnu.jel.CompilationException
public static gnu.jel.CompiledExpression[] compileExpressions(StarTableJELRowReader reader, String[] exprs) throws IOException
Any CompilationExceptions are rethrown as IOExceptions; this method should therefore generally be used only if the expressions are expected to be free from errors (have been compiled before).
reader
- table readerexprs
- strings giving JEL expressions to be compiledIOException
- in case of any CompilationExceptionpublic static IOException toIOException(gnu.jel.CompilationException e, String expr)
e
- compilation exceptionexpr
- expression for which compilation failed,
to be reported in error messagepublic static Class<?> getWrapperType(Class<?> clazz)
clazz
is a non-primitive type, it will be returned,
otherwise the wrapper class corresponding to the primitive type
of clazz
will be returned
(e.g. Integer
for int
).clazz
- input classclazz
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.