Class ScriptedBiFunction<T,U,V>
java.lang.Object
net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
net.shibboleth.utilities.java.support.logic.ScriptedBiFunction<T,U,V>
- Type Parameters:
T
- first input typeU
- second input typeV
- return type
- All Implemented Interfaces:
BiFunction<T,U,V>
public class ScriptedBiFunction<T,U,V> extends AbstractScriptEvaluator implements BiFunction<T,U,V>
A
BiFunction
which calls out to a supplied script.- Since:
- 8.2.0
-
Field Summary
Fields Modifier and Type Field Description private Pair<Class<T>,Class<U>>
inputTypes
Input types.private org.slf4j.Logger
log
Class logger.Fields inherited from class net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
DEFAULT_ENGINE
-
Constructor Summary
Constructors Modifier Constructor Description protected
ScriptedBiFunction(EvaluableScript theScript)
Constructor.protected
ScriptedBiFunction(EvaluableScript theScript, String extraInfo)
Constructor. -
Method Summary
Modifier and Type Method Description V
apply(T first, U second)
Pair<Class<T>,Class<U>>
getInputTypes()
Get the input type to be enforced.static <T, U, V> ScriptedBiFunction<T,U,V>
inlineScript(String scriptSource)
Factory to createScriptedBiFunction
from inline data.static <T, U, V> ScriptedBiFunction<T,U,V>
inlineScript(String engineName, String scriptSource)
Factory to createScriptedBiFunction
from inline data.protected void
prepareContext(ScriptContext scriptContext, Object... input)
Pre-process the script context before execution.static <T, U, V> ScriptedBiFunction<T,U,V>
resourceScript(String engineName, Resource resource)
Factory to createScriptedBiFunction
from aResource
.static <T, U, V> ScriptedBiFunction<T,U,V>
resourceScript(Resource resource)
Factory to createScriptedBiFunction
from aResource
.void
setInputTypes(Pair<Class<T>,Class<U>> types)
Set the input types to be enforced.void
setOutputType(Class<?> type)
Set the output type to be enforced.void
setReturnOnError(Object value)
Set value to return if an error occurs.Methods inherited from class net.shibboleth.utilities.java.support.scripting.AbstractScriptEvaluator
evaluate, finalizeContext, getCustomObject, getHideExceptions, getLogPrefix, getOutputType, getReturnOnError, setCustomObject, setHideExceptions, setLogPrefix
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.function.BiFunction
andThen
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
inputTypes
Input types.
-
-
Constructor Details
-
ScriptedBiFunction
protected ScriptedBiFunction(@Nonnull @NotEmpty @ParameterName(name="theScript") EvaluableScript theScript, @Nullable @NotEmpty @ParameterName(name="extraInfo") String extraInfo)Constructor.- Parameters:
theScript
- the script we will evaluate.extraInfo
- debugging information.
-
ScriptedBiFunction
protected ScriptedBiFunction(@Nonnull @NotEmpty @ParameterName(name="theScript") EvaluableScript theScript)Constructor.- Parameters:
theScript
- the script we will evaluate.
-
-
Method Details
-
getInputTypes
Get the input type to be enforced.- Returns:
- input type
-
setInputTypes
Set the input types to be enforced.- Parameters:
types
- the input types
-
setOutputType
Set the output type to be enforced.- Overrides:
setOutputType
in classAbstractScriptEvaluator
- Parameters:
type
- output type
-
setReturnOnError
Set value to return if an error occurs.- Overrides:
setReturnOnError
in classAbstractScriptEvaluator
- Parameters:
value
- value to return
-
apply
- Specified by:
apply
in interfaceBiFunction<T,U,V>
-
prepareContext
Pre-process the script context before execution.- Specified by:
prepareContext
in classAbstractScriptEvaluator
- Parameters:
scriptContext
- the script contextinput
- the input
-
resourceScript
public static <T, U, V> ScriptedBiFunction<T,U,V> resourceScript(@Nonnull @NotEmpty String engineName, @Nonnull Resource resource) throws ScriptException, IOExceptionFactory to createScriptedBiFunction
from aResource
.- Type Parameters:
T
- first input typeU
- second input typeV
- return type- Parameters:
resource
- the resource to look atengineName
- the language- Returns:
- the function
- Throws:
ScriptException
- if the compile failsIOException
- if the file doesn't exist.
-
resourceScript
public static <T, U, V> ScriptedBiFunction<T,U,V> resourceScript(Resource resource) throws ScriptException, IOExceptionFactory to createScriptedBiFunction
from aResource
.- Type Parameters:
T
- first input typeU
- second input typeV
- return type- Parameters:
resource
- the resource to look at- Returns:
- the function
- Throws:
ScriptException
- if the compile failsIOException
- if the file doesn't exist.
-
inlineScript
public static <T, U, V> ScriptedBiFunction<T,U,V> inlineScript(@Nonnull @NotEmpty String engineName, @Nonnull @NotEmpty String scriptSource) throws ScriptExceptionFactory to createScriptedBiFunction
from inline data.- Type Parameters:
T
- first input typeU
- second input typeV
- return type- Parameters:
scriptSource
- the script, as a stringengineName
- the language- Returns:
- the function
- Throws:
ScriptException
- if the compile fails
-
inlineScript
public static <T, U, V> ScriptedBiFunction<T,U,V> inlineScript(@Nonnull @NotEmpty String scriptSource) throws ScriptExceptionFactory to createScriptedBiFunction
from inline data.- Type Parameters:
T
- first input typeU
- second input typeV
- return type- Parameters:
scriptSource
- the script, as a string- Returns:
- the function
- Throws:
ScriptException
- if the compile fails
-