public final class Lambdas
extends java.lang.Object
Note that scripting performance is typically 10-100 slower than the same JIT compiled Java expression.
See the scripting articles about how to script in java.
Note that a script engines might not be thread safe, e.g., you might not run multiple scripts without external synchronization. See also THREADING for further details.
| Modifier and Type | Method and Description |
|---|---|
static Action0 |
action0(java.lang.String expression,
javax.script.ScriptEngine engine,
java.util.Map<java.lang.String,java.lang.Object> bindings)
Returns a parameterless action which invokes the given script on the
script engine.
|
static Action0 |
action0(java.lang.String expression,
javax.script.ScriptEngine engine,
java.lang.Object... nameThenObject)
Creates a parameterless action which executes the given script with the
given script engine.
|
static <T> Action1<T> |
action1(java.lang.String expression,
javax.script.ScriptEngine engine,
java.util.Map<java.lang.String,java.lang.Object> bindings)
Creates a single parameter action which invokes the script engine with a given
expression.
|
static <T> Action1<T> |
action1(java.lang.String expression,
javax.script.ScriptEngine engine,
java.lang.Object... nameThenObject)
Creates a single parameter action which executes the given script on
the script engine.
|
static Action0 |
as0(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> bindings)
Creates a parameterless action which executes the given script as JavaScript.
|
static Action0 |
as0(java.lang.String expression,
java.lang.Object... nameThenObject)
Creates a parameterless action which executes the given script as
javascript.
|
static <T> Action1<T> |
as1(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> bindings)
Creates a single parameter action which executes the given script as JavaScript.
|
static <T> Action1<T> |
as1(java.lang.String expression,
java.lang.Object... nameThenObject)
Creates a single parameter action which executes the given script as JavaScript.
|
static javax.script.ScriptEngine |
getEngine(java.lang.String name)
Retrieve a script engine for the given name.
|
static <T> Func0<T> |
js0(java.lang.String expression)
Returns a parameterless function which invokes the given javascript
and retunrs its value.
|
static <T> Func0<T> |
js0(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> bindings)
Returns a parameterless function which invokes the given javascript
and retunrs its value.
|
static <T> Func0<T> |
js0(java.lang.String expression,
java.lang.Object... nameThenObject)
Creates a parameterless function which executes the given script as
javascript.
|
static <T,U> Func1<T,U> |
js1(java.lang.String expression)
Creates a single parameter function which invokes the script engine with a given
expression and returns its result.
|
static <T,U> Func1<T,U> |
js1(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> bindings)
Creates a single parameter function which invokes the script engine with a given
expression and returns its result.
|
static <T,U> Func1<T,U> |
js1(java.lang.String expression,
java.lang.Object... nameThenObject)
Creates a single parameter function which executes the given script as
javascript.
|
static <T,U,V> Func2<T,U,V> |
js2(java.lang.String expression)
Creates a two parameter function which invokes the script engine with a given
expression and returns its result.
|
static <T,U,V> Func2<T,U,V> |
js2(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> bindings)
Creates a two parameter function which invokes the script engine with a given
expression and returns its result.
|
static <T,U,V> Func2<T,U,V> |
js2(java.lang.String expression,
java.lang.Object... nameThenObject)
Creates a two parameter function which executes the given script as
javascript.
|
static <T> Func0<T> |
script0(java.lang.String expression,
javax.script.ScriptEngine engine,
java.util.Map<java.lang.String,java.lang.Object> bindings)
Returns a parameterless function which invokes the given script on the
script engine and retunrs its value.
|
static <T> Func0<T> |
script0(java.lang.String expression,
javax.script.ScriptEngine engine,
java.lang.Object... nameThenObject)
Creates a parameterless function which executes the given script as
javascript.
|
static <T,U> Func1<U,T> |
script1(java.lang.String expression,
javax.script.ScriptEngine engine,
java.util.Map<java.lang.String,java.lang.Object> bindings)
Creates a single parameter function which invokes the script engine with a given
expression and returns its result.
|
static <T,U> Func1<T,U> |
script1(java.lang.String expression,
javax.script.ScriptEngine engine,
java.lang.Object... nameThenObject)
Creates a single parameter function which executes the given script as
javascript.
|
static <T,U,V> Func2<U,V,T> |
script2(java.lang.String expression,
javax.script.ScriptEngine engine,
java.util.Map<java.lang.String,java.lang.Object> bindings)
Creates a two parameter function which invokes the script engine with a given
expression and returns its result.
|
static <T,U,V> Func2<T,U,V> |
script2(java.lang.String expression,
javax.script.ScriptEngine engine,
java.lang.Object... nameThenObject)
Creates a two parameter function which executes the given script as
javascript.
|
@Nonnull public static Action0 action0(@Nonnull java.lang.String expression, @Nonnull javax.script.ScriptEngine engine, @Nonnull java.util.Map<java.lang.String,java.lang.Object> bindings)
The syntax of the expression follows the generic lambda format used throughout this utility class:
=> expression1; expression;
You may omit the => completely.
expression - the original lambda expressionengine - the script engine to usebindings - the external resources the script might need@Nonnull public static Action0 action0(@Nonnull java.lang.String expression, @Nonnull javax.script.ScriptEngine engine, @Nonnull java.lang.Object... nameThenObject)
"ref1", 1, "ref2", 2.0.
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;expression - the lambda expressionengine - the scripting engine to usenameThenObject - the String, Object, String, Object, ... sequence of name and value pairs.@Nonnull public static <T> Action1<T> action1(@Nonnull java.lang.String expression, @Nonnull javax.script.ScriptEngine engine, @Nonnull java.util.Map<java.lang.String,java.lang.Object> bindings)
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression;T - the parameter type of the actionexpression - the lambda expressionengine - the engine to run the expressionbindings - the external resources the script might need@Nonnull public static <T> Action1<T> action1(@Nonnull java.lang.String expression, @Nonnull javax.script.ScriptEngine engine, @Nonnull java.lang.Object... nameThenObject)
"ref1", 1, "ref2", 2.0.
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the parameter type of the actionexpression - the lambda expressionengine - the script engine to usenameThenObject - the String, Object, String, Object, ... sequence of name and value pairs.@Nonnull public static Action0 as0(@Nonnull java.lang.String expression, @Nonnull java.util.Map<java.lang.String,java.lang.Object> bindings)
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;expression - the lambda expressionbindings - the extra parameter bingings@Nonnull public static Action0 as0(@Nonnull java.lang.String expression, @Nonnull java.lang.Object... nameThenObject)
"ref1", 1, "ref2", 2.0.
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;expression - the lambda expressionnameThenObject - the String, Object, String, Object, ... sequence of name and value pairs.@Nonnull public static <T> Action1<T> as1(@Nonnull java.lang.String expression, @Nonnull java.util.Map<java.lang.String,java.lang.Object> bindings)
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the parameter type of the actionexpression - the lambda expressionbindings - the extra parameter bindings@Nonnull public static <T> Action1<T> as1(@Nonnull java.lang.String expression, @Nonnull java.lang.Object... nameThenObject)
"ref1", 1, "ref2", 2.0.
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the parameter type of the actionexpression - the lambda expressionnameThenObject - the String, Object, String, Object, ... sequence of name and value pairs.@Nonnull
public static javax.script.ScriptEngine getEngine(@Nonnull
java.lang.String name)
new ScriptEngineManager().getEngineByName(name) call.
Might throw an IllegalArgumentException if there is no such engine
by the name.name - the script engine name. For javascript, you may use js.@Nonnull public static <T> Func0<T> js0(@Nonnull java.lang.String expression)
The syntax of the expression follows the generic lambda format used throughout this utility class:
=> expression1; expression; return result
For zero parameters, you may omit the => completely.
T - the return type of the functionexpression - the lambda expression@Nonnull public static <T> Func0<T> js0(@Nonnull java.lang.String expression, @Nonnull java.util.Map<java.lang.String,java.lang.Object> bindings)
The syntax of the expression follows the generic lambda format used throughout this utility class:
=> expression1; expression; return result
For zero parameters, you may omit the => completely.
T - the return type of the functionexpression - the lambda expressionbindings - the external resources the script might need@Nonnull public static <T> Func0<T> js0(@Nonnull java.lang.String expression, @Nonnull java.lang.Object... nameThenObject)
"ref1", 1, "ref2", 2.0.
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the result typeexpression - the lambda expressionnameThenObject - the String, Object, String, Object, ... sequence of name and value pairs.@Nonnull public static <T,U> Func1<T,U> js1(@Nonnull java.lang.String expression)
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the result type of the functionU - the parameter typeexpression - the lambda expression@Nonnull public static <T,U> Func1<T,U> js1(@Nonnull java.lang.String expression, @Nonnull java.util.Map<java.lang.String,java.lang.Object> bindings)
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the result type of the functionU - the parameter typeexpression - the lambda expressionbindings - the external resources the script might need@Nonnull public static <T,U> Func1<T,U> js1(@Nonnull java.lang.String expression, @Nonnull java.lang.Object... nameThenObject)
"ref1", 1, "ref2", 2.0.
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the result typeU - the parameter type of the functionexpression - the lambda expressionnameThenObject - the String, Object, String, Object, ... sequence of name and value pairs.@Nonnull public static <T,U,V> Func2<T,U,V> js2(@Nonnull java.lang.String expression)
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName1, paramName2 => expression1; expression; return result;T - the result type of the functionU - the first parameter typeV - the second parameter typeexpression - the lambda expression@Nonnull public static <T,U,V> Func2<T,U,V> js2(@Nonnull java.lang.String expression, @Nonnull java.util.Map<java.lang.String,java.lang.Object> bindings)
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName1, paramName2 => expression1; expression; return result;T - the result type of the functionU - the first parameter typeV - the second parameter typeexpression - the lambda expressionbindings - the external resources the script might need@Nonnull public static <T,U,V> Func2<T,U,V> js2(@Nonnull java.lang.String expression, @Nonnull java.lang.Object... nameThenObject)
"ref1", 1, "ref2", 2.0.
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the result typeU - the first parameter typeV - the second parameter typeexpression - the lambda expressionnameThenObject - the String, Object, String, Object, ... sequence of name and value pairs.@Nonnull public static <T> Func0<T> script0(@Nonnull java.lang.String expression, @Nonnull javax.script.ScriptEngine engine, @Nonnull java.util.Map<java.lang.String,java.lang.Object> bindings)
The syntax of the expression follows the generic lambda format used throughout this utility class:
param1, param2 => expression1; expression; return result
For zero parameters, you may omit the => completely.
T - the return type of the functionexpression - the original lambda expressionengine - the script engine to usebindings - the external resources the script might need@Nonnull public static <T> Func0<T> script0(@Nonnull java.lang.String expression, @Nonnull javax.script.ScriptEngine engine, @Nonnull java.lang.Object... nameThenObject)
"ref1", 1, "ref2", 2.0.
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the result typeexpression - the lambda expressionengine - the scripting engine to usenameThenObject - the String, Object, String, Object, ... sequence of name and value pairs.@Nonnull public static <T,U> Func1<U,T> script1(@Nonnull java.lang.String expression, @Nonnull javax.script.ScriptEngine engine, @Nonnull java.util.Map<java.lang.String,java.lang.Object> bindings)
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the result type of the functionU - the parameter typeexpression - the lambda expressionengine - the engine to run the expressionbindings - the external resources the script might need@Nonnull public static <T,U> Func1<T,U> script1(@Nonnull java.lang.String expression, @Nonnull javax.script.ScriptEngine engine, @Nonnull java.lang.Object... nameThenObject)
"ref1", 1, "ref2", 2.0.
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the result typeU - the parameter type of the functionexpression - the lambda expressionengine - the script engine to usenameThenObject - the String, Object, String, Object, ... sequence of name and value pairs.@Nonnull public static <T,U,V> Func2<U,V,T> script2(@Nonnull java.lang.String expression, @Nonnull javax.script.ScriptEngine engine, @Nonnull java.util.Map<java.lang.String,java.lang.Object> bindings)
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName1, paramName2 => expression1; expression; return result;T - the result type of the functionU - the first parameter typeV - the second parameter typeexpression - the lambda expressionengine - the engine to run the expressionbindings - the external resources the script might need@Nonnull public static <T,U,V> Func2<T,U,V> script2(@Nonnull java.lang.String expression, @Nonnull javax.script.ScriptEngine engine, @Nonnull java.lang.Object... nameThenObject)
"ref1", 1, "ref2", 2.0.
The syntax of the expression follows the generic lambda format used throughout this utility class:
paramName => expression1; expression; return result;T - the result typeU - the first parameter typeV - the second parameter typeexpression - the lambda expressionengine - the script engine to usenameThenObject - the String, Object, String, Object, ... sequence of name and value pairs.