GridGain™ 3.6.0e
Enterprise Edition

org.gridgain.grid.lang
Class GridJexlPredicate<T>

java.lang.Object
  extended by org.gridgain.grid.lang.GridMetadataAwareAdapter
      extended by org.gridgain.grid.lang.GridLambdaAdapter
          extended by org.gridgain.grid.lang.GridPredicate<T>
              extended by org.gridgain.grid.lang.GridJexlPredicate<T>
Type Parameters:
T - Type of the free variable, i.e. the element the closure is called on.
All Implemented Interfaces:
Serializable, Cloneable, GridMetadataAware, GridPeerDeployAware, GridLambda

public class GridJexlPredicate<T>
extends GridPredicate<T>

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.

Wiki & Forum:


Wiki
Forum

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

Constructor Summary
GridJexlPredicate()
          Creates JEXL predicate with no expression, variable binding or additional context.
GridJexlPredicate(String exprStr)
          Creates JEXL predicate with given parameters.
GridJexlPredicate(String exprStr, String var)
          Creates JEXL predicate with given parameters.
 
Method Summary
 boolean apply(T t)
          Predicate body.
 String toString()
          
 GridJexlPredicate<T> with(GridTuple2<String,Object>... vals)
          Sets JEXL context variables' values and returns this.
 GridJexlPredicate<T> with(String var, Object val)
          Sets JEXL context variable value and returns this.
 
Methods inherited from class org.gridgain.grid.lang.GridPredicate
andThen, andThen, andThen, compose, compose, compose, compose, curry, uncurry2, uncurry3
 
Methods inherited from class org.gridgain.grid.lang.GridLambdaAdapter
classLoader, deployClass, peerDeployLike, withMeta
 
Methods inherited from class org.gridgain.grid.lang.GridMetadataAwareAdapter
addMeta, addMetaIfAbsent, addMetaIfAbsent, allMeta, clone, copyMeta, copyMeta, hasMeta, hasMeta, meta, putMetaIfAbsent, putMetaIfAbsent, readExternalMeta, removeMeta, removeMeta, replaceMeta, writeExternalMeta
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.gridgain.grid.GridMetadataAware
addMeta, addMetaIfAbsent, addMetaIfAbsent, allMeta, copyMeta, copyMeta, hasMeta, hasMeta, meta, putMetaIfAbsent, putMetaIfAbsent, removeMeta, removeMeta, replaceMeta
 

Constructor Detail

GridJexlPredicate

public GridJexlPredicate()
Creates JEXL predicate with no expression, variable binding or additional context. Note that such predicate will always evaluate to false.


GridJexlPredicate

public GridJexlPredicate(String exprStr,
                         String var)
Creates JEXL predicate with given parameters.

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

GridJexlPredicate

public GridJexlPredicate(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 GridJexlPredicate<T> 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 GridJexlPredicate<T> 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
                     T t)
Predicate body.

Specified by:
apply in class GridPredicate<T>
Parameters:
t - 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™ 3.6.0e
Enterprise Edition

GridGain - Real Time Big Data
Enterprise Edition, ver. 3.6.0e.13012012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Follow GridGain on Facebook Join GridGain User Group Follow GridGain on Twitter Follow GridGain on YouTube