public class ExpressionEvaluator extends java.lang.Object implements Changeable
Modifier and Type | Class and Description |
---|---|
static class |
ExpressionEvaluator.TypeSafeComparator
Comparator class for doing typesafe comparisons and sorting.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.Map |
baseObjects
base objects of the expression evaluator
|
static int |
OBJECTTYPE_ANY
constant for any value type
|
static int |
OBJECTTYPE_ASSIGNMENT
constant for the value type "assignment (result)"
|
static int |
OBJECTTYPE_BINARY
constant for binary value type
|
static int |
OBJECTTYPE_BOOLEAN
constant for the value type "boolean"
|
static int |
OBJECTTYPE_COLLECTION
constant for the value type "collection"
|
static int |
OBJECTTYPE_DATE
constant for the value type "date"
|
static int |
OBJECTTYPE_NULL
constant for the value type "null" (object is expected to be null)
|
static int |
OBJECTTYPE_NUMBER
constant for the value type "number"
|
static int |
OBJECTTYPE_STRING
constant for the value type "string"
|
static int |
OBJECTTYPE_UNKNOWN
constant for unknown value type
|
static int |
OBJECTTYPE_WILDCARDSTRING
constant for the value type "string"
|
protected PropertyResolver |
resolver
PropertyResolver
|
Constructor and Description |
---|
ExpressionEvaluator()
Create a new instance of the expression evaluator
|
Modifier and Type | Method and Description |
---|---|
boolean |
canResolve()
Check whether the resolvable is capable of resolving properties right
now.
|
void |
clearProperties()
Clear all resolvable properties
|
static boolean |
containsAll(java.util.Collection leftCollection,
java.util.Collection rightCollection)
Check whether the left collection contains all objects from the right
collection
|
static boolean |
containsNone(java.util.Collection leftCollection,
java.util.Collection rightCollection)
Check whether the collections have no object in common
|
static boolean |
containsOneOf(java.util.Collection leftCollection,
java.util.Collection rightCollection)
Check whether the left collection contains at least one object of the
right collection
|
void |
filter(Expression expression,
java.util.List<Resolvable> resolvables)
Filter the given list of resolvables with the given expression.
|
java.lang.Object |
get(java.lang.String key)
Get the property named by key or null if the property does not exist or
is not set.
|
static byte[] |
getAsBinary(java.lang.Object object)
Get the given object as binary.
|
static java.lang.Boolean |
getAsBoolean(java.lang.Object object)
Get the given object as boolean.
|
static java.util.Collection |
getAsCollection(java.lang.Object object)
Get the given object as Collection.
|
static java.util.Date |
getAsDate(java.lang.Object object)
Get the given object as Date.
|
static java.lang.Number |
getAsNumber(ExpressionQueryRequest request,
java.lang.Object object,
java.lang.Class numberClass) |
static java.lang.Number |
getAsNumber(java.lang.Object object)
Get the given object as number.
|
static java.lang.Number |
getAsNumber(java.lang.Object object,
java.lang.Class numberClass)
Get the given object as number of the given class.
|
static java.lang.String |
getAsString(java.lang.Object object)
Get the given object as String.
|
static java.lang.Object |
getAsType(java.lang.Object object,
int type)
Get the given object as object of specified type.
|
protected static int |
getObjectType(java.lang.Object object)
Analyze the given object and get the objecttype
|
java.lang.Object |
getProperty(java.lang.String key)
Get the property named by key or null if the property does not exist or
is not set.
|
protected static java.lang.String |
getTypeName(java.lang.Object object)
Get the type of the object as string
|
static java.lang.String |
getValuetypeName(int valueType)
Get the name of the given value type
|
protected static boolean |
incompatibleComparisonTypes(java.lang.Object object1,
java.lang.Object object2)
Helper method to throw an Exception "Incompatible types found in
comparison..."
|
static boolean |
isInteger(java.lang.Number number)
Check whether the given number is an integer.
|
static boolean |
isTypeSafeEqual(java.lang.Object object1,
java.lang.Object object2)
Check whether the objects are typesafe equal.
|
static boolean |
isTypeSafeUnequal(java.lang.Object object1,
java.lang.Object object2)
Check whether the objects are typesafe unequal.
|
boolean |
match(Expression expression)
Try to match the given expression (against the added resolvables)
|
boolean |
match(Expression expression,
Resolvable matchedObject)
Try to match the given expression against the given object (and the added resolvables)
|
boolean |
setProperty(java.lang.String name,
java.lang.Object value)
Set (modify) the property name to resolve to the given value
|
void |
setRequestParameters(java.util.Map parameters)
Allows you to set parameters which will be passed to
ExpressionQueryRequest |
void |
setResolver(PropertyResolver resolver)
Set a property resolver, which will be used to resolve paths in expressions
|
static boolean |
typeSafeComparison(ExpressionQueryRequest request,
java.lang.Object object1,
java.lang.Object object2,
int type)
Perform a typesafe comparison between the given objects.
|
public static final int OBJECTTYPE_ANY
public static final int OBJECTTYPE_NULL
public static final int OBJECTTYPE_BOOLEAN
public static final int OBJECTTYPE_NUMBER
public static final int OBJECTTYPE_DATE
public static final int OBJECTTYPE_STRING
public static final int OBJECTTYPE_WILDCARDSTRING
public static final int OBJECTTYPE_COLLECTION
public static final int OBJECTTYPE_ASSIGNMENT
public static final int OBJECTTYPE_UNKNOWN
public static final int OBJECTTYPE_BINARY
protected java.util.Map baseObjects
protected PropertyResolver resolver
public ExpressionEvaluator()
public void setResolver(PropertyResolver resolver)
resolver
- property resolverpublic static java.lang.String getValuetypeName(int valueType)
valueType
- value typepublic void setRequestParameters(java.util.Map parameters)
ExpressionQueryRequest
parameters
- request parameterspublic boolean match(Expression expression) throws ExpressionParserException
expression
- expression to matchExpressionParserException
- when the expression cannot be matched (is not
boolean or contains errors)public boolean match(Expression expression, Resolvable matchedObject) throws ExpressionParserException
expression
- expression to matchmatchedObject
- object the expression is matched againstExpressionParserException
- when the expression cannot be matched (is not
boolean or contains errors)public void filter(Expression expression, java.util.List<Resolvable> resolvables) throws ExpressionParserException
expression
- expressionresolvables
- list of resolvables, must not be null and must be modifiableExpressionParserException
- when filtering failspublic static java.lang.Number getAsNumber(java.lang.Object object, java.lang.Class numberClass) throws EvaluationException
object
- object to interpret as numbernumberClass
- desired class, must be a subclass of NumberEvaluationException
- when the object cannot be interpreted as
number or the given numberClass is not derived from class Numberpublic static java.lang.Number getAsNumber(ExpressionQueryRequest request, java.lang.Object object, java.lang.Class numberClass) throws EvaluationException
EvaluationException
public static java.lang.Number getAsNumber(java.lang.Object object) throws EvaluationException
Number
, its string representation is parsed as number.object
- object to interpret as numberEvaluationException
- when the object cannot be interpreted as
numberpublic static java.lang.Boolean getAsBoolean(java.lang.Object object) throws EvaluationException
Boolean
, its string representation is parsed as boolean. "true",
"false", "1" or "0" can be interpreted as boolean.object
- object to interpret as booleanEvaluationException
- when the object cannot be interpreted as
booleanpublic static java.util.Date getAsDate(java.lang.Object object) throws EvaluationException
Date
.object
- object to interpret as DateEvaluationException
- when the object cannot be interpreted as Datepublic static java.util.Collection getAsCollection(java.lang.Object object) throws EvaluationException
Collection
, a new collection containing just the object is
returned.object
- object to interpret as collectionEvaluationException
- when evaluation failspublic static java.lang.String getAsString(java.lang.Object object) throws EvaluationException
Collection
.object
- object to interpret as stringEvaluationException
- when the object cannot be interpreted as
stringpublic static byte[] getAsBinary(java.lang.Object object) throws EvaluationException
object
- object to get as binary dataEvaluationException
- when evaluation failspublic static java.lang.Object getAsType(java.lang.Object object, int type) throws EvaluationException
OBJECTTYPE_ANY
,
OBJECTTYPE_BOOLEAN
, OBJECTTYPE_COLLECTION
,
OBJECTTYPE_DATE
, OBJECTTYPE_NULL
,
OBJECTTYPE_NUMBER
, OBJECTTYPE_STRING
).object
- object to interpret in the given typetype
- requested type for the objectEvaluationException
- when the object cannot be interpreted in the
given typepublic static boolean isInteger(java.lang.Number number)
Long
,
Integer
, Short
, Byte
, BigInteger
number
- number to checkprotected static java.lang.String getTypeName(java.lang.Object object)
object
- object to analyzeprotected static boolean incompatibleComparisonTypes(java.lang.Object object1, java.lang.Object object2) throws EvaluationException
object1
- first object in comparisonobject2
- second object in comparisonEvaluationException
- since this is the purpose of this methodpublic static boolean typeSafeComparison(ExpressionQueryRequest request, java.lang.Object object1, java.lang.Object object2, int type) throws EvaluationException
Function.TYPE_SMALLER
,
Function.TYPE_SMALLEROREQUAL
,
Function.TYPE_GREATEROREQUAL
, Function.TYPE_GREATER
).request
- object.object1
- lefthand-side objectobject2
- righthand-side objecttype
- type of the comparisonEvaluationException
- when the objects cannot be converted such
that the comparison can be donepublic static boolean isTypeSafeUnequal(java.lang.Object object1, java.lang.Object object2) throws EvaluationException
isTypeSafeEqual(Object, Object)
, when object1 is an instance
of NestedCollection
. In this case, the comparison is interpreted
as: "true when object1 contains at least one object that is unequal
object2"object1
- lefthand-side objectobject2
- righthand-side objectEvaluationException
- when the objects cannot be comparedpublic static boolean isTypeSafeEqual(java.lang.Object object1, java.lang.Object object2) throws EvaluationException
object1
- lefthand-side objectobject2
- righthand-side objectEvaluationException
- when the objects cannot be comparedprotected static int getObjectType(java.lang.Object object) throws EvaluationException
object
- object to analyzeEvaluationException
- when evaluation failspublic static boolean containsOneOf(java.util.Collection leftCollection, java.util.Collection rightCollection) throws EvaluationException
leftCollection
- left collectionrightCollection
- right collectionEvaluationException
- when evaluation failspublic static boolean containsNone(java.util.Collection leftCollection, java.util.Collection rightCollection) throws EvaluationException
leftCollection
- left collectionrightCollection
- right collectionEvaluationException
- when evaluation failspublic static boolean containsAll(java.util.Collection leftCollection, java.util.Collection rightCollection)
leftCollection
- left collectionrightCollection
- right collectionpublic boolean setProperty(java.lang.String name, java.lang.Object value) throws InsufficientPrivilegesException
Changeable
setProperty
in interface Changeable
name
- name of the property to set/modifyvalue
- (new) value to setInsufficientPrivilegesException
- when the property may not be
changedpublic java.lang.Object getProperty(java.lang.String key)
Resolvable
Resolvable.get(String)
.getProperty
in interface Resolvable
key
- key of the propertypublic java.lang.Object get(java.lang.String key)
Resolvable
get
in interface Resolvable
key
- key of the propertypublic boolean canResolve()
Resolvable
Resolvable.getProperty(String)
or Resolvable.get(String)
will return null.canResolve
in interface Resolvable
public void clearProperties()
Copyright © 2018 Gentics Software. All Rights Reserved.