public abstract class BaseFunction extends Object implements Function
Subclasses must either use the constructor that specifies a name, or be called something that ends with "Function" – in which case the name will automatically be generated from the class name. "MyAwesomeFunction" will get the name "my_awesome", i.e. the camel cased name will be converted to snake case, minus the "Function" suffix.
Subclasses must override the callFunction(io.burt.jmespath.Adapter<T>, java.util.List<io.burt.jmespath.function.FunctionArgument<T>>) method, and not
call(io.burt.jmespath.Adapter<T>, java.util.List<io.burt.jmespath.function.FunctionArgument<T>>). The latter does type checking on the arguments and then calls
callFunction(io.burt.jmespath.Adapter<T>, java.util.List<io.burt.jmespath.function.FunctionArgument<T>>).
Subclasses must also provide argument constraints for checking arguments.
This is done by using the ArgumentConstraints DSL and passing the
result in a super call in the constructor.
| Constructor and Description |
|---|
BaseFunction(ArgumentConstraint... argumentConstraints)
Constructor used by subclasses whose name ends with "Function" and that
accept a fixed number of argument.
|
BaseFunction(ArgumentConstraint argumentConstraints)
Constructor used by subclasses whose name ends with "Function" and that
accept a single, or a variable number of arguments.
|
BaseFunction(String name,
ArgumentConstraint... argumentConstraints)
Constructor used by subclasses that provide a custom name (not based on
the class name) and that accept a fixed number of arguments.
|
BaseFunction(String name,
ArgumentConstraint argumentConstraints)
Constructor used by subclasses that provide a custom name (not based on
the class name) and that accept a single, or a variable number of arguments.
|
| Modifier and Type | Method and Description |
|---|---|
ArgumentConstraint |
argumentConstraints()
Returns the constraints to use when checking the list of arguments before
the function is called.
|
<T> T |
call(Adapter<T> runtime,
List<FunctionArgument<T>> arguments)
Call this function with a list of arguments.
|
protected abstract <T> T |
callFunction(Adapter<T> runtime,
List<FunctionArgument<T>> arguments)
Called from
call(io.burt.jmespath.Adapter<T>, java.util.List<io.burt.jmespath.function.FunctionArgument<T>>) after the argument constraints have been checked
against the arguments. |
String |
name()
Returns the name of the function.
|
public BaseFunction(ArgumentConstraint argumentConstraints)
FunctionConfigurationException - when the function name cannot be produced from the class namepublic BaseFunction(ArgumentConstraint... argumentConstraints)
FunctionConfigurationException - when the function name cannot be produced from the class namepublic BaseFunction(String name, ArgumentConstraint... argumentConstraints)
public BaseFunction(String name, ArgumentConstraint argumentConstraints)
public String name()
FunctionThe name is either automatically generated from the class name, or explicitly specified in the constructor.
public ArgumentConstraint argumentConstraints()
FunctionargumentConstraints in interface Functionpublic <T> T call(Adapter<T> runtime, List<FunctionArgument<T>> arguments)
protected abstract <T> T callFunction(Adapter<T> runtime, List<FunctionArgument<T>> arguments)
call(io.burt.jmespath.Adapter<T>, java.util.List<io.burt.jmespath.function.FunctionArgument<T>>) after the argument constraints have been checked
against the arguments.
May perform additional type checking and throw ArgumentTypeException.
For example when using expressions there is currently no way to check the
types produced by those expressions without running the function. Functions
that accept expressions are responsible for checking the types of the values
produced by those expressions.
Copyright © 2016–2023. All rights reserved.