public class ExpressionFactory extends java.lang.Object implements IExpressionFactory, IExpressionConstants
| Modifier and Type | Field and Description |
|---|---|
static Variable |
EVERYTHING |
protected static java.util.Map<java.lang.String,java.lang.reflect.Constructor<?>> |
functionMap |
static IExpressionFactory |
INSTANCE |
static Variable |
THIS |
FUNC_BOOLEAN, FUNC_CLASS, FUNC_FILTER, FUNC_RANGE, FUNC_VERSION, NO_ARGSKEYWORD_ALL, KEYWORD_BOOLEAN, KEYWORD_CLASS, KEYWORD_COLLECT, KEYWORD_EXISTS, KEYWORD_FALSE, KEYWORD_FILTER, KEYWORD_FIRST, KEYWORD_FLATTEN, KEYWORD_INTERSECT, KEYWORD_IQUERY, KEYWORD_LATEST, KEYWORD_LIMIT, KEYWORD_LOCALIZED_KEYS, KEYWORD_LOCALIZED_MAP, KEYWORD_LOCALIZED_PROPERTY, KEYWORD_NULL, KEYWORD_RANGE, KEYWORD_SATISFIES_ALL, KEYWORD_SATISFIES_ANY, KEYWORD_SELECT, KEYWORD_SET, KEYWORD_TRAVERSE, KEYWORD_TRUE, KEYWORD_UNION, KEYWORD_UNIQUE, KEYWORD_VERSION, OPERATOR_AND, OPERATOR_ARRAY, OPERATOR_ASSIGN, OPERATOR_AT, OPERATOR_EACH, OPERATOR_ELSE, OPERATOR_EQUALS, OPERATOR_GT, OPERATOR_GT_EQUAL, OPERATOR_IF, OPERATOR_LT, OPERATOR_LT_EQUAL, OPERATOR_MATCHES, OPERATOR_MEMBER, OPERATOR_NOT, OPERATOR_NOT_EQUALS, OPERATOR_OR, OPERATOR_PARAMETER, PRIORITY_AND, PRIORITY_ASSIGNMENT, PRIORITY_BINARY, PRIORITY_COLLECTION, PRIORITY_COMMA, PRIORITY_CONDITION, PRIORITY_FUNCTION, PRIORITY_LAMBDA, PRIORITY_LITERAL, PRIORITY_MAX, PRIORITY_MEMBER, PRIORITY_NOT, PRIORITY_OR, PRIORITY_VARIABLE, VARIABLE_EVERYTHING, VARIABLE_THIS| Constructor and Description |
|---|
ExpressionFactory() |
| Modifier and Type | Method and Description |
|---|---|
IExpression |
all(IExpression collection,
IExpression lambda)
Create a collection filter that yields true if the
lambda yields true for
all of the elements of the collection |
IExpression |
and(IExpression... operands)
Create a logical and of its
operands. |
IExpression |
array(IExpression... operands)
Create an array of elements.
|
IExpression |
assignment(IExpression variable,
IExpression expression)
Creates an expression that represents a variable assignment
|
IExpression |
at(IExpression target,
IExpression key)
Create an lookup of
key in the target. |
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 a
test and then, depending on the outcome,
evaluates either ifTrue or ifFalse. |
IExpression |
constant(java.lang.Object value)
Creates an expression that evaluates to the constant
value. |
<T> IContextExpression<T> |
contextExpression(IExpression expression,
java.lang.Object... parameters)
Creates a top level expression that represents a full query.
|
protected static Expression[] |
convertArray(IExpression[] operands) |
IEvaluationContext |
createContext(IExpression[] variables,
java.lang.Object... parameters)
Create an evaluation context with one single variable
|
IEvaluationContext |
createContext(java.lang.Object... parameters)
Create an evaluation context with one single variable
|
IExpression |
equals(IExpression lhs,
IExpression rhs)
Create an expression that tests if
lhs is equal to rhs. |
IExpression |
exists(IExpression collection,
IExpression lambda)
Create a collection filter that yields true if the
lambda yields true for
at least one of the elements of the collection |
IFilterExpression |
filterExpression(IExpression expression)
Creates a top level expression suitable for predicate matching
|
IExpression |
first(IExpression collection,
IExpression lambda)
Create an expression that yields the first element of the
collection for which the lambda yields true. |
IExpression |
flatten(IExpression collection)
Intended to be applied on collections of collections.
|
IExpression |
function(java.lang.Object function,
IExpression... args)
Given one of the values in the map returned by
IExpressionFactory.getFunctionMap(), this method
returns a function expression. |
java.util.Map<java.lang.String,? extends java.lang.Object> |
getFunctionMap()
Returns a map of functions supported by this factory.
|
IExpression |
greater(IExpression lhs,
IExpression rhs)
Create an expression that tests if
lhs is greater than rhs. |
IExpression |
greaterEqual(IExpression lhs,
IExpression rhs)
Create an expression that tests if
lhs is greater than or equal to rhs. |
IExpression |
indexedParameter(int index)
Creates an indexed parameter expression
|
IExpression |
intersect(IExpression c1,
IExpression c2)
Create an intersection of
c1 and c2 |
IExpression |
lambda(IExpression variable,
IExpression body)
Creates a lambda expression that takes exactly one variable.
|
IExpression |
lambda(IExpression variable,
IExpression[] assignments,
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 the
collection. |
IExpression |
less(IExpression lhs,
IExpression rhs)
Create an expression that tests if
lhs is less than rhs. |
IExpression |
lessEqual(IExpression lhs,
IExpression rhs)
Create an expression that tests if
lhs is less than or equal to rhs. |
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 by
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.
|
IExpression |
matches(IExpression lhs,
IExpression rhs)
Create an expression that tests if
lhs matches rhs. |
<T> IMatchExpression<T> |
matchExpression(IExpression expression,
java.lang.Object... parameters)
Creates a parameterized top level expression suitable for predicate matching
|
IExpression |
member(IExpression target,
java.lang.String name)
Creates a member accessor expression.
|
IExpression |
memberCall(IExpression target,
java.lang.String name,
IExpression... args)
Creates a member call expression.
|
IExpression |
normalize(java.util.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 its
operand. |
IExpression |
or(IExpression... operands)
Create a logical or of its
operands. |
IExpression |
pipe(IExpression... operands)
Create a pipe of expressions.
|
IExpression |
select(IExpression collection,
IExpression lambda)
Create an expression that yields a new collection consisting of all elements of the
collection for which the lambda yields true. |
IExpression |
thisVariable()
Returns the variable that represents
this in an expression |
IExpression |
toExpression(IQuery<?> query)
Wrap an
IQuery as an expression. |
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.
|
IExpression |
union(IExpression c1,
IExpression c2)
Create a union of
c1 and c2 |
IExpression |
unique(IExpression collection,
IExpression cache)
Create an expression that yields a new collection where each element is unique.
|
IExpression |
variable(java.lang.String name)
Creates an expression that represents a variable
|
public static final Variable EVERYTHING
protected static final java.util.Map<java.lang.String,java.lang.reflect.Constructor<?>> functionMap
public static final IExpressionFactory INSTANCE
public static final Variable THIS
protected static Expression[] convertArray(IExpression[] operands)
public IExpression all(IExpression collection, IExpression lambda)
IExpressionFactorylambda yields true for
all of the elements of the collectionall in interface IExpressionFactorycollection - The collection providing the elements to testlambda - The lambda that performs the testpublic IExpression and(IExpression... operands)
IExpressionFactoryoperands.and in interface IExpressionFactoryoperands - The boolean operandspublic IExpression array(IExpression... operands)
IExpressionFactoryarray in interface IExpressionFactoryoperands - The elements of the arraypublic IExpression assignment(IExpression variable, IExpression expression)
IExpressionFactoryassignment in interface IExpressionFactoryvariable - The variableexpression - The expression that yields the value to assign to the variablepublic IExpression at(IExpression target, IExpression key)
IExpressionFactorykey in the target.
The key expression should evaluate to a string or an integer.at in interface IExpressionFactorytarget - The target for the lookupkey - The key to use for the lookuppublic IExpression collect(IExpression collection, IExpression lambda)
IExpressionFactorycollect in interface IExpressionFactorycollection - The collection providing the elements to evaluatelambda - The lambda that creates each new elementpublic IExpression condition(IExpression test, IExpression ifTrue, IExpression ifFalse)
IExpressionFactorytest and then, depending on the outcome,
evaluates either ifTrue or ifFalse. The expression yields the result
of the ifTrue or ifFalse evaluation.condition in interface IExpressionFactorytest - The testifTrue - The code to evaluate when the test evaluates to trueifFalse - The code to evaluate when the test evaluates to falsepublic IExpression constant(java.lang.Object value)
IExpressionFactoryvalue.constant in interface IExpressionFactoryvalue - The constantpublic <T> IContextExpression<T> contextExpression(IExpression expression, java.lang.Object... parameters)
IExpressionFactorycontextExpression in interface IExpressionFactoryexpression - The queryparameters - The parameters of the querypublic IEvaluationContext createContext(IExpression[] variables, java.lang.Object... parameters)
IExpressionFactorycreateContext in interface IExpressionFactoryvariables - The variables that will be maintained by the contextparameters - Indexed parameters to use in the expressionpublic IEvaluationContext createContext(java.lang.Object... parameters)
IExpressionFactorycreateContext in interface IExpressionFactoryparameters - Indexed parameters to use in the expressionpublic IExpression equals(IExpression lhs, IExpression rhs)
IExpressionFactorylhs is equal to rhs.equals in interface IExpressionFactorylhs - The left hand side value.rhs - The right hand side value.public IExpression exists(IExpression collection, IExpression lambda)
IExpressionFactorylambda yields true for
at least one of the elements of the collectionexists in interface IExpressionFactorycollection - The collection providing the elements to testlambda - The lambda that performs the testpublic IFilterExpression filterExpression(IExpression expression)
IExpressionFactoryfilterExpression in interface IExpressionFactoryexpression - The boolean expressionpublic IExpression first(IExpression collection, IExpression lambda)
IExpressionFactorycollection for which the lambda yields true.first in interface IExpressionFactorycollection - The collection providing the elements to testlambda - The lambda that performs the testpublic IExpression flatten(IExpression collection)
IExpressionFactoryflatten in interface IExpressionFactorycollection - The collection providing the collections that provides all elementspublic IExpression function(java.lang.Object function, IExpression... args)
IExpressionFactoryIExpressionFactory.getFunctionMap(), this method
returns a function expression.function in interface IExpressionFactoryfunction - The value obtained from the map.args - The arguments to evaluate and pass when evaluating the function.public java.util.Map<java.lang.String,? extends java.lang.Object> getFunctionMap()
IExpressionFactoryIExpressionFactory.function(Object, IExpression[])
method.getFunctionMap in interface IExpressionFactorypublic IExpression greater(IExpression lhs, IExpression rhs)
IExpressionFactorylhs is greater than rhs.greater in interface IExpressionFactorylhs - The left hand side value.rhs - The right hand side value.public IExpression greaterEqual(IExpression lhs, IExpression rhs)
IExpressionFactorylhs is greater than or equal to rhs.greaterEqual in interface IExpressionFactorylhs - The left hand side value.rhs - The right hand side value.public IExpression indexedParameter(int index)
IExpressionFactoryindexedParameter in interface IExpressionFactoryindex - The index to usepublic IExpression intersect(IExpression c1, IExpression c2)
IExpressionFactoryc1 and c2intersect in interface IExpressionFactoryc1 - first collectionc2 - second collectionpublic IExpression lambda(IExpression variable, IExpression body)
IExpressionFactorylambda in interface IExpressionFactoryvariable - The element variable that the lambda usesbody - The body of the lambdapublic IExpression lambda(IExpression variable, IExpression[] assignments, IExpression body)
IExpressionFactorylambda in interface IExpressionFactoryvariable - The element variable that the lambda usesassignments - Assignments to evaluate once before calling the body for each element.body - The body of the lambdapublic IExpression latest(IExpression collection)
IExpressionFactorycollection. Each element in collection
must implement the IVersionedId interface.latest in interface IExpressionFactorycollection - The collection providing the versioned elementspublic IExpression less(IExpression lhs, IExpression rhs)
IExpressionFactorylhs is less than rhs.less in interface IExpressionFactorylhs - The left hand side value.rhs - The right hand side value.public IExpression lessEqual(IExpression lhs, IExpression rhs)
IExpressionFactorylhs is less than or equal to rhs.lessEqual in interface IExpressionFactorylhs - The left hand side value.rhs - The right hand side value.public IExpression limit(IExpression collection, IExpression limit)
IExpressionFactorylimit.limit in interface IExpressionFactorycollection - The source collectionlimit - The expression that evaluates to the element count limitpublic IExpression limit(IExpression collection, int count)
IExpressionFactorylimit in interface IExpressionFactorycollection - The source collectioncount - The element count limitpublic IExpression matches(IExpression lhs, IExpression rhs)
IExpressionFactorylhs matches rhs.matches in interface IExpressionFactorylhs - The left hand side value.rhs - The right hand side value.public <T> IMatchExpression<T> matchExpression(IExpression expression, java.lang.Object... parameters)
IExpressionFactorymatchExpression in interface IExpressionFactoryexpression - The boolean expressionparameters - The parameters to use in the callpublic IExpression member(IExpression target, java.lang.String name)
IExpressionFactorymember in interface IExpressionFactorytarget - The target for the member accessname - The name of the memberpublic IExpression memberCall(IExpression target, java.lang.String name, IExpression... args)
IExpressionFactorymemberCall in interface IExpressionFactorytarget - The target for the member callname - The name of the memberargs - The arguments to use for the callpublic IExpression normalize(java.util.List<? extends IExpression> operands, int expressionType)
IExpressionFactorynormalize in interface IExpressionFactoryoperands - The operands to normalizeexpressionType - The type (must be either IExpression.TYPE_AND
or IExpression.TYPE_OR.public IExpression not(IExpression operand)
IExpressionFactoryoperand.not in interface IExpressionFactoryoperand - The boolean expression to negatepublic IExpression or(IExpression... operands)
IExpressionFactoryoperands.or in interface IExpressionFactoryoperands - The boolean operandspublic IExpression pipe(IExpression... operands)
IExpressionFactorypipe in interface IExpressionFactoryoperands - The expressions that make out the pipepublic IExpression select(IExpression collection, IExpression lambda)
IExpressionFactorycollection for which the lambda yields true.select in interface IExpressionFactorycollection - The collection providing the elements to testlambda - The lambda that performs the testpublic IExpression thisVariable()
IExpressionFactorythis in an expressionthisVariable in interface IExpressionFactorythis variable.public IExpression toExpression(IQuery<?> query)
IExpressionFactoryIQuery as an expression.toExpression in interface IExpressionFactorypublic IExpression traverse(IExpression collection, IExpression lambda)
IExpressionFactoryRecursively 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.
traverse in interface IExpressionFactorycollection - The collection providing the elements to testlambda - The lambda that collects the children for the next iterationpublic IExpression union(IExpression c1, IExpression c2)
IExpressionFactoryc1 and c2union in interface IExpressionFactoryc1 - first collectionc2 - second collectionpublic IExpression unique(IExpression collection, IExpression cache)
IExpressionFactorycache can be provided if the uniqueness should span a larger
scope then just the source collection.unique in interface IExpressionFactorycollection - The source collectioncache - Optional cache to use when uniqueness should span over several invocationspublic IExpression variable(java.lang.String name)
IExpressionFactoryvariable in interface IExpressionFactoryname - The name of the variable