GridGain™ 4.3.1e
Enterprise "Big Data" Edition

org.gridgain.grid.lang
Class GridJexlPredicate2<T1,T2>

java.lang.Object
  extended by org.gridgain.grid.lang.GridLambdaAdapter
      extended by org.gridgain.grid.lang.GridPredicate2<T1,T2>
          extended by org.gridgain.grid.lang.GridJexlPredicate2<T1,T2>
Type Parameters:
T1 - Type of the first free variable, i.e. the element the closure is called on.
T2 - Type of the second free variable, i.e. the element the closure is called on.
All Implemented Interfaces:
Serializable, GridPeerDeployAware, GridLambda

public class GridJexlPredicate2<T1,T2>
extends GridPredicate2<T1,T2>

Defines a predicate based on Apache JEXL 2.0 boolean expression.

Predicate like closure is a first-class function that is defined with (or closed over) its free variables that are bound to the closure scope at execution.

JEXL predicate binds free variables to JEXL context either with default names or with names supplied by the caller. If bind name is not provided the default name is elemN, where N is 1-based index of the variable. The following code snippet (using GridJexlPredicate2 as an example):

 ...
 // Create new JEXL predicate with default binding names.
 new GridJexlPredicate2<String, String>("elem1.length > 0 elem2.length == elem1.length");
 ...
 
is identical to this one:
 ...
 // Create new JEXL predicate with custom binding names.
 new GridJexlPredicate2<String, String>("s1.length > 0 && s1.length == s2.length", "s1", "s2");
 ...
 
Typedefs and factory methods from GridFunc class can be used to shorten the generics code and provide for convenient and terse code when working with predicates (as well as with closures and tuples):
 ...
 // Similar as above using typedefs and factory methods.
 F.x2("s1.length > 0 && s1.length == s2.length", "s1", "s2");
 // Additional context.
 F.x2("s1.length > n && s1.length == s2.length", "s1", "s2").with("n", 10);
 ...
 

Thread Safety

This class does not provide synchronization and caller must ensure an outside synchronization if this predicate is to be used from multiple threads.

See Also:
GridFunc.x2(String), GridFunc.x2(String, String, String), Serialized Form
 

Constructor Summary
GridJexlPredicate2()
          Creates JEXL predicate with no expression, variable binding or additional context.
GridJexlPredicate2(String exprStr)
          Creates JEXL predicate with given parameters.
GridJexlPredicate2(String exprStr, String var1)
          Creates JEXL predicate with given parameters.
GridJexlPredicate2(String exprStr, String var1, String var2)
          Creates JEXL predicate with given parameters.
 
Method Summary
 boolean apply(T1 t1, T2 t2)
          Predicate body.
 String toString()
          
 GridJexlPredicate2<T1,T2> with(GridTuple2<String,Object>... vals)
          Sets JEXL context variables' values and returns this.
 GridJexlPredicate2<T1,T2> with(String var, Object val)
          Sets JEXL context variable value and returns this.
 
Methods inherited from class org.gridgain.grid.lang.GridPredicate2
andThen, andThen, andThen, curry, curry, uncurry3
 
Methods inherited from class org.gridgain.grid.lang.GridLambdaAdapter
classLoader, deployClass, peerDeployLike
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GridJexlPredicate2

public GridJexlPredicate2()
Creates JEXL predicate with no expression, variable binding or additional context. Note that if no JEXL expression is set the predicate will always return false.


GridJexlPredicate2

public GridJexlPredicate2(String exprStr,
                          String var1)
Creates JEXL predicate with given parameters. Note that since second parameter name is not provided, it will be initialized to default, which is elem2.

Parameters:
exprStr - JEXL boolean expression. Note that non-boolean return value will evaluate this predicate to false.
var1 - Name of the 1st bound variable in JEXL expression.

GridJexlPredicate2

public GridJexlPredicate2(String exprStr,
                          String var1,
                          String var2)
Creates JEXL predicate with given parameters.

Parameters:
exprStr - JEXL boolean expression. Note that non-boolean return value will evaluate this predicate to false.
var1 - Name of the 1st bound variable in JEXL expression.
var2 - Name of the 2nd bound variable in JEXL expression.

GridJexlPredicate2

public GridJexlPredicate2(String exprStr)
Creates JEXL predicate with given parameters. Name of the bound variable will be elem.

Parameters:
exprStr - JEXL boolean expression. Note that non-boolean return value will evaluate this predicate to false.
Method Detail

with

public GridJexlPredicate2<T1,T2> with(String var,
                                      @Nullable
                                      Object val)
Sets JEXL context variable value and returns this.

Parameters:
var - Name of the variable in JEXL context (new or existing).
val - Value to be set or overridden in JEXL context.
Returns:
This predicate so that this call can be chained.

with

public GridJexlPredicate2<T1,T2> with(GridTuple2<String,Object>... vals)
Sets JEXL context variables' values and returns this.

Parameters:
vals - Set of tuples representing JEXL context to be bound. First element in the tuple represents the name and the second element represents its value in the context.
Returns:
This predicate so that this call can be chained.

apply

public boolean apply(@Nullable
                     T1 t1,
                     @Nullable
                     T2 t2)
Predicate body.

Specified by:
apply in class GridPredicate2<T1,T2>
Parameters:
t1 - First bound free variable, i.e. the element the closure is called or closed on.
t2 - Second bound free variable, i.e. the element the closure is called or closed on.
Returns:
Return value.

toString

public String toString()

Overrides:
toString in class Object

GridGain™ 4.3.1e
Enterprise "Big Data" Edition

GridGain - In-Memory Big Data
Enterprise "Big Data" Edition, ver. 4.3.1e.10112012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Join GridGain User Group Follow GridGain on Twitter Follow GridGain on Vimeo