Interface IExpressionFactory
-
public interface IExpressionFactory
This interface provides all the factory methods needed to create the nodes of the expression tree.- Since:
- 2.0
- Restriction:
- This interface is not intended to be implemented directly by clients.
- Restriction:
- This interface is not intended to be extended directly by clients.
-
-
Field Summary
Fields Modifier and Type Field Description static String
FUNC_BOOLEAN
static String
FUNC_CLASS
static String
FUNC_FILTER
static String
FUNC_RANGE
static String
FUNC_VERSION
static IExpression[]
NO_ARGS
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description IExpression
all(IExpression collection, IExpression lambda)
Create a collection filter that yields true if thelambda
yields true for all of the elements of thecollection
IExpression
and(IExpression... operands)
Create a logical and of itsoperands
.IExpression
array(IExpression... elements)
Create an array of elements.IExpression
assignment(IExpression variable, IExpression expression)
Creates an expression that represents a variable assignmentIExpression
at(IExpression target, IExpression key)
Create an lookup ofkey
in thetarget
.IExpression
collect(IExpression collection, IExpression lambda)
Create an expression that collects the result of evaluating each element in a new collection.IExpression
condition(IExpression test, IExpression ifTrue, IExpression ifFalse)
Create an expression that first evaluates atest
and then, depending on the outcome, evaluates eitherifTrue
orifFalse
.IExpression
constant(Object value)
Creates an expression that evaluates to the constantvalue
.<T> IContextExpression<T>
contextExpression(IExpression expr, Object... parameters)
Creates a top level expression that represents a full query.IEvaluationContext
createContext(Object... params)
Create an evaluation context with one single variableIEvaluationContext
createContext(IExpression[] variables, Object... params)
Create an evaluation context with one single variableIExpression
equals(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
is equal torhs
.IExpression
exists(IExpression collection, IExpression lambda)
Create a collection filter that yields true if thelambda
yields true for at least one of the elements of thecollection
IFilterExpression
filterExpression(IExpression expression)
Creates a top level expression suitable for predicate matchingIExpression
first(IExpression collection, IExpression lambda)
Create an expression that yields the first element of thecollection
for which thelambda
yieldstrue
.IExpression
flatten(IExpression collection)
Intended to be applied on collections of collections.IExpression
function(Object function, IExpression... args)
Given one of the values in the map returned bygetFunctionMap()
, this method returns a function expression.Map<String,? extends Object>
getFunctionMap()
Returns a map of functions supported by this factory.IExpression
greater(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
is greater thanrhs
.IExpression
greaterEqual(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
is greater than or equal torhs
.IExpression
indexedParameter(int index)
Creates an indexed parameter expressionIExpression
intersect(IExpression c1, IExpression c2)
Create an intersection ofc1
andc2
IExpression
lambda(IExpression variable, IExpression body)
Creates a lambda expression that takes exactly one variable.IExpression
lambda(IExpression variable, IExpression[] initialAssignments, IExpression body)
Creates a lambda expression that takes more then one variable (currying).IExpression
latest(IExpression collection)
Create an expression that yields a new collection consisting of the latest version of the elements of thecollection
.IExpression
less(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
is less thanrhs
.IExpression
lessEqual(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
is less than or equal torhs
.IExpression
limit(IExpression collection, int count)
Create an expression that yields a new collection consisting of the count first elements of the source collection.IExpression
limit(IExpression collection, IExpression limit)
Create an expression that yields a new collection consisting of the n first elements of the source collection where n is determined bylimit
.IExpression
matches(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
matchesrhs
.<T> IMatchExpression<T>
matchExpression(IExpression expression, Object... parameters)
Creates a parameterized top level expression suitable for predicate matchingIExpression
member(IExpression target, String name)
Creates a member accessor expression.IExpression
memberCall(IExpression target, String name, IExpression... args)
Creates a member call expression.IExpression
normalize(List<? extends IExpression> operands, int expressionType)
Performs boolean normalization on the expression to create a canonical form.IExpression
not(IExpression operand)
Creates an expression that negates the result of evaluating itsoperand
.IExpression
or(IExpression... operands)
Create a logical or of itsoperands
.IExpression
pipe(IExpression... expressions)
Create a pipe of expressions.IExpression
select(IExpression collection, IExpression lambda)
Create an expression that yields a new collection consisting of all elements of thecollection
for which thelambda
yieldstrue
.IExpression
thisVariable()
Returns the variable that representsthis
in an expressionIExpression
toExpression(IQuery<?> query)
Wrap anIQuery
as an expression.IExpression
traverse(IExpression collection, IExpression lambda)
Recursively traverse and collect elements based on a conditionIExpression
union(IExpression c1, IExpression c2)
Create a union ofc1
andc2
IExpression
unique(IExpression collection, IExpression cache)
Create an expression that yields a new collection where each element is unique.IExpression
variable(String name)
Creates an expression that represents a variable
-
-
-
Field Detail
-
FUNC_BOOLEAN
static final String FUNC_BOOLEAN
- See Also:
- Constant Field Values
-
FUNC_VERSION
static final String FUNC_VERSION
- See Also:
- Constant Field Values
-
FUNC_CLASS
static final String FUNC_CLASS
- See Also:
- Constant Field Values
-
FUNC_RANGE
static final String FUNC_RANGE
- See Also:
- Constant Field Values
-
FUNC_FILTER
static final String FUNC_FILTER
- See Also:
- Constant Field Values
-
NO_ARGS
static final IExpression[] NO_ARGS
-
-
Method Detail
-
all
IExpression all(IExpression collection, IExpression lambda)
Create a collection filter that yields true if thelambda
yields true for all of the elements of thecollection
- Parameters:
collection
- The collection providing the elements to testlambda
- The lambda that performs the test- Returns:
- A boolean expression
-
and
IExpression and(IExpression... operands)
Create a logical and of itsoperands
.- Parameters:
operands
- The boolean operands- Returns:
- A boolean expression
-
assignment
IExpression assignment(IExpression variable, IExpression expression)
Creates an expression that represents a variable assignment- Parameters:
variable
- The variableexpression
- The expression that yields the value to assign to the variable- Returns:
- An assignment expression
-
collect
IExpression collect(IExpression collection, IExpression lambda)
Create an expression that collects the result of evaluating each element in a new collection.- Parameters:
collection
- The collection providing the elements to evaluatelambda
- The lambda that creates each new element- Returns:
- A collection expression
-
condition
IExpression condition(IExpression test, IExpression ifTrue, IExpression ifFalse)
Create an expression that first evaluates atest
and then, depending on the outcome, evaluates eitherifTrue
orifFalse
. The expression yields the result of theifTrue
orifFalse
evaluation.- Parameters:
test
- The testifTrue
- The code to evaluate when the test evaluates totrue
ifFalse
- The code to evaluate when the test evaluates tofalse
- Returns:
- The conditional expression
-
first
IExpression first(IExpression collection, IExpression lambda)
Create an expression that yields the first element of thecollection
for which thelambda
yieldstrue
.- Parameters:
collection
- The collection providing the elements to testlambda
- The lambda that performs the test- Returns:
- An element expression
-
flatten
IExpression flatten(IExpression collection)
Intended to be applied on collections of collections. Yields a single collection with all elements from the source collections, in the order they are evaluated.- Parameters:
collection
- The collection providing the collections that provides all elements- Returns:
- A collection expression
-
lambda
IExpression lambda(IExpression variable, IExpression[] initialAssignments, IExpression body)
Creates a lambda expression that takes more then one variable (currying). Suitable for use in most collection expressions.- Parameters:
variable
- The element variable that the lambda usesbody
- The body of the lambdainitialAssignments
- Assignments to evaluate once before calling the body for each element.- Returns:
- A lambda expression with currying
-
memberCall
IExpression memberCall(IExpression target, String name, IExpression... args)
Creates a member call expression.- Parameters:
target
- The target for the member callname
- The name of the memberargs
- The arguments to use for the call- Returns:
- A member expression
-
traverse
IExpression traverse(IExpression collection, IExpression lambda)
Recursively traverse and collect elements based on a condition
A common scenario in p2 is that you want to start with a set of roots and then find all items that fulfill the root requirements. Those items in turn introduce new requirements so you want to find them too. The process continues until no more requirements can be satisfied. This type of query can be performed using the traverse function.
The function will evaluate an expression, once for each element, collect elements for which the evaluation returned true, then then re-evaluate using the collected result as source of elements. No element is evaluated twice. This continues until no more elements are found.
- Parameters:
collection
- The collection providing the elements to testlambda
- The lambda that collects the children for the next iteration- Returns:
- A collection expression
-
unique
IExpression unique(IExpression collection, IExpression cache)
Create an expression that yields a new collection where each element is unique. An optionalcache
can be provided if the uniqueness should span a larger scope then just the source collection.- Parameters:
collection
- The source collectioncache
- Optional cache to use when uniqueness should span over several invocations- Returns:
- A collection expression
-
array
IExpression array(IExpression... elements)
Create an array of elements.- Parameters:
elements
- The elements of the array- Returns:
- An array expression
-
at
IExpression at(IExpression target, IExpression key)
Create an lookup ofkey
in thetarget
. The key expression should evaluate to a string or an integer.- Parameters:
target
- The target for the lookupkey
- The key to use for the lookup- Returns:
- A lookup expression
-
createContext
IEvaluationContext createContext(Object... params)
Create an evaluation context with one single variable- Parameters:
params
- Indexed parameters to use in the expression- Returns:
- the context
-
createContext
IEvaluationContext createContext(IExpression[] variables, Object... params)
Create an evaluation context with one single variable- Parameters:
params
- Indexed parameters to use in the expressionvariables
- The variables that will be maintained by the context- Returns:
- the context
-
constant
IExpression constant(Object value)
Creates an expression that evaluates to the constantvalue
.- Parameters:
value
- The constant- Returns:
- A constant expression
-
contextExpression
<T> IContextExpression<T> contextExpression(IExpression expr, Object... parameters)
Creates a top level expression that represents a full query.- Parameters:
expr
- The queryparameters
- The parameters of the query- Returns:
- A top level query expression
-
equals
IExpression equals(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
is equal torhs
.- Parameters:
lhs
- The left hand side value.rhs
- The right hand side value.- Returns:
- A boolean expression
-
exists
IExpression exists(IExpression collection, IExpression lambda)
Create a collection filter that yields true if thelambda
yields true for at least one of the elements of thecollection
- Parameters:
collection
- The collection providing the elements to testlambda
- The lambda that performs the test- Returns:
- A boolean expression
-
filterExpression
IFilterExpression filterExpression(IExpression expression)
Creates a top level expression suitable for predicate matching- Parameters:
expression
- The boolean expression- Returns:
- A top level predicate expression
-
function
IExpression function(Object function, IExpression... args)
Given one of the values in the map returned bygetFunctionMap()
, this method returns a function expression.- Parameters:
function
- The value obtained from the map.args
- The arguments to evaluate and pass when evaluating the function.- Returns:
- A function expression
-
getFunctionMap
Map<String,? extends Object> getFunctionMap()
Returns a map of functions supported by this factory. The map is keyed by function names and the value is an object suitable to pass to thefunction(Object, IExpression[])
method.- Returns:
- A key/function map.
-
greater
IExpression greater(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
is greater thanrhs
.- Parameters:
lhs
- The left hand side value.rhs
- The right hand side value.- Returns:
- A boolean expression
-
greaterEqual
IExpression greaterEqual(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
is greater than or equal torhs
.- Parameters:
lhs
- The left hand side value.rhs
- The right hand side value.- Returns:
- A boolean expression
-
indexedParameter
IExpression indexedParameter(int index)
Creates an indexed parameter expression- Parameters:
index
- The index to use- Returns:
- a parameter expression
-
intersect
IExpression intersect(IExpression c1, IExpression c2)
Create an intersection ofc1
andc2
- Parameters:
c1
- first collectionc2
- second collection- Returns:
- An intersect expression
-
lambda
IExpression lambda(IExpression variable, IExpression body)
Creates a lambda expression that takes exactly one variable. Suitable for use in most collection expressions.- Parameters:
variable
- The element variable that the lambda usesbody
- The body of the lambda- Returns:
- A lambda expression
-
latest
IExpression latest(IExpression collection)
Create an expression that yields a new collection consisting of the latest version of the elements of thecollection
. Each element incollection
must implement theIVersionedId
interface.- Parameters:
collection
- The collection providing the versioned elements- Returns:
- A collection expression
-
less
IExpression less(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
is less thanrhs
.- Parameters:
lhs
- The left hand side value.rhs
- The right hand side value.- Returns:
- A boolean expression
-
lessEqual
IExpression lessEqual(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
is less than or equal torhs
.- Parameters:
lhs
- The left hand side value.rhs
- The right hand side value.- Returns:
- A boolean expression
-
limit
IExpression limit(IExpression collection, int count)
Create an expression that yields a new collection consisting of the count first elements of the source collection.- Parameters:
collection
- The source collectioncount
- The element count limit- Returns:
- A collection expression
-
limit
IExpression limit(IExpression collection, IExpression limit)
Create an expression that yields a new collection consisting of the n first elements of the source collection where n is determined bylimit
.- Parameters:
collection
- The source collectionlimit
- The expression that evaluates to the element count limit- Returns:
- A collection expression
-
normalize
IExpression normalize(List<? extends IExpression> operands, int expressionType)
Performs boolean normalization on the expression to create a canonical form.- Parameters:
operands
- The operands to normalizeexpressionType
- The type (must be eitherIExpression.TYPE_AND
orIExpression.TYPE_OR
.- Returns:
- The normalized expression
-
matches
IExpression matches(IExpression lhs, IExpression rhs)
Create an expression that tests iflhs
matchesrhs
.- Parameters:
lhs
- The left hand side value.rhs
- The right hand side value.- Returns:
- A boolean expression
-
matchExpression
<T> IMatchExpression<T> matchExpression(IExpression expression, Object... parameters)
Creates a parameterized top level expression suitable for predicate matching- Parameters:
expression
- The boolean expressionparameters
- The parameters to use in the call- Returns:
- A top level predicate expression
-
member
IExpression member(IExpression target, String name)
Creates a member accessor expression.- Parameters:
target
- The target for the member accessname
- The name of the member- Returns:
- A member expression
-
not
IExpression not(IExpression operand)
Creates an expression that negates the result of evaluating itsoperand
.- Parameters:
operand
- The boolean expression to negate- Returns:
- A boolean expression
-
or
IExpression or(IExpression... operands)
Create a logical or of itsoperands
.- Parameters:
operands
- The boolean operands- Returns:
- A boolean expression
-
pipe
IExpression pipe(IExpression... expressions)
Create a pipe of expressions.- Parameters:
expressions
- The expressions that make out the pipe- Returns:
- A pipe expression
-
select
IExpression select(IExpression collection, IExpression lambda)
Create an expression that yields a new collection consisting of all elements of thecollection
for which thelambda
yieldstrue
.- Parameters:
collection
- The collection providing the elements to testlambda
- The lambda that performs the test- Returns:
- A collection expression
-
thisVariable
IExpression thisVariable()
Returns the variable that representsthis
in an expression- Returns:
- The
this
variable.
-
toExpression
IExpression toExpression(IQuery<?> query)
Wrap anIQuery
as an expression.- Parameters:
query
- The query to wrap.- Returns:
- An expression that wraps the query
-
union
IExpression union(IExpression c1, IExpression c2)
Create a union ofc1
andc2
- Parameters:
c1
- first collectionc2
- second collection- Returns:
- A union expression
-
variable
IExpression variable(String name)
Creates an expression that represents a variable- Parameters:
name
- The name of the variable- Returns:
- A variable expression
-
-