Class FunctionUtils
java.lang.Object
com.api.jsonata4java.expressions.utils.FunctionUtils
- All Implemented Interfaces:
Serializable
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddArrayExprVarContext(MappingExpressionParser.ExprContext ctx, MappingExpressionParser.ExprValuesContext evc, com.fasterxml.jackson.databind.node.ArrayNode arrayNode) Extends a suppliedMappingExpressionParser.ExprValuesContextusing the supplied context and array node contentaddIndexExprVarContext(MappingExpressionParser.ExprContext ctx, MappingExpressionParser.ExprValuesContext evc, Integer index) Extends anMappingExpressionParser.ExprValuesContextusing the context containing the supplied index valueaddObjectExprVarContext(MappingExpressionParser.ExprContext ctx, MappingExpressionParser.ExprValuesContext evc, com.fasterxml.jackson.databind.node.ObjectNode object) Extends anMappingExpressionParser.ExprValuesContextusing the context containing the supplied object valueaddStringExprVarContext(MappingExpressionParser.ExprContext ctx, MappingExpressionParser.ExprValuesContext evc, String string) Extends anMappingExpressionParser.ExprValuesContextusing the context containing the supplied string valuestatic booleancheckArgument(ExpressionsVisitor exprVisitor, MappingExpressionParser.ExprContext exprCtx, String signature) Tests whether the supplied exprCtx meets the signature expectations.fillExprVarContext(int fctVarCount, MappingExpressionParser.ExprContext ctx, com.fasterxml.jackson.databind.JsonNode... elements) Creates anMappingExpressionParser.ExprValuesContextcontaining a parenthesized comma separated variable list of the supplied elementsgetArrayConstructorContext(MappingExpressionParser.ExprContext ctx, com.fasterxml.jackson.databind.node.ArrayNode array) Creates anMappingExpressionParser.Array_constructorContextfrom the supplied context and arraystatic com.fasterxml.jackson.databind.JsonNodegetContextVariable(ExpressionsVisitor exprVisitor) Retrieve the latest context variable from theExpressionsVisitorstack, allowing for a null to be returned (in lieu of a NullNode)static com.fasterxml.jackson.databind.JsonNodegetContextVariableOrNullNode(ExpressionsVisitor exprVisitor) Retrieve the latest context variable from theExpressionsVisitorstackstatic DeclaredFunctiongetFunctionArgFromCtx(ExpressionsVisitor expressionVisitor, MappingExpressionParser.Function_callContext ctx, boolean useContext) getObjectConstructorContext(MappingExpressionParser.ExprContext ctx, com.fasterxml.jackson.databind.node.ObjectNode object) Creates anMappingExpressionParser.Object_constructorContextfrom the supplied context and objectstatic intgetOptionalArgCount(String signature) static com.fasterxml.jackson.databind.JsonNodegetValuesListExpression(ExpressionsVisitor exprVisitor, MappingExpressionParser.Function_callContext ctx, int index) Gets the expression at the supplied index from the context'sMappingExpressionParser.ExprValuesContextMappingExpressionParser.ExprListContext, preserving the null value (or returning null if the index is invalid)static com.fasterxml.jackson.databind.JsonNodegetValuesListExpressionOrNullNode(ExpressionsVisitor exprVisitor, MappingExpressionParser.Function_callContext ctx, int index) Gets the expression at the supplied index from the context's {link ExprValuesContext} {link ExprListContext]static com.fasterxml.jackson.databind.JsonNodeprocessFctCallVariables(ExpressionsVisitor exprVisitor, FunctionBase function, org.antlr.v4.runtime.tree.TerminalNode varid, MappingExpressionParser.Function_callContext ctx, com.fasterxml.jackson.databind.JsonNode value, String key, com.fasterxml.jackson.databind.node.ObjectNode object) Creates anMappingExpressionParser.ExprListContextcontaining the parenthesized comma separated variable list of JsonNode elements, sets it in the supplied context (ctx) and then executes the function to return its result.static com.fasterxml.jackson.databind.JsonNodeprocessVariablesCallFunction(ExpressionsVisitor exprVisitor, FunctionBase function, org.antlr.v4.runtime.tree.TerminalNode varid, MappingExpressionParser.Function_callContext ctx, com.fasterxml.jackson.databind.JsonNode... elements) Creates anMappingExpressionParser.ExprListContextcontaining the parenthesized comma separated variable list of JsonNode elements, sets it in the supplied context (ctx) and then executes the function to return its result.static booleanuseContextVariable(FunctionBase fct, MappingExpressionParser.Function_callContext ctx, String signature) Determine if the function should use the context variable as its first parameterstatic voidvalidateArguments(String possibleException, ExpressionsVisitor exprVisitor, MappingExpressionParser.Function_callContext ctx, int index, String signature) Checks the expression at the supplied index from the context'sMappingExpressionParser.ExprValuesContextMappingExpressionParser.ExprListContext, preserving the null value (or returning null if the index is invalid) to determine if the arguments are valid according to the supplied signature
-
Constructor Details
-
FunctionUtils
public FunctionUtils()
-
-
Method Details
-
addArrayExprVarContext
public static MappingExpressionParser.ExprValuesContext addArrayExprVarContext(MappingExpressionParser.ExprContext ctx, MappingExpressionParser.ExprValuesContext evc, com.fasterxml.jackson.databind.node.ArrayNode arrayNode) Extends a suppliedMappingExpressionParser.ExprValuesContextusing the supplied context and array node content- Parameters:
ctx- context to serve as a parent context and provide invoking stateevc- expression values context to be updatedarrayNode- array values to be added to the expression values context- Returns:
MappingExpressionParser.ExprValuesContextupdated with the supplied context and array context
-
addIndexExprVarContext
public static MappingExpressionParser.ExprValuesContext addIndexExprVarContext(MappingExpressionParser.ExprContext ctx, MappingExpressionParser.ExprValuesContext evc, Integer index) Extends anMappingExpressionParser.ExprValuesContextusing the context containing the supplied index value- Parameters:
ctx- context to serve as a parent context and provide invoking stateevc- expression values context to be updatedindex- value to be added to the expression values context- Returns:
MappingExpressionParser.ExprValuesContextupdated using the context containing the supplied index value
-
addObjectExprVarContext
public static MappingExpressionParser.ExprValuesContext addObjectExprVarContext(MappingExpressionParser.ExprContext ctx, MappingExpressionParser.ExprValuesContext evc, com.fasterxml.jackson.databind.node.ObjectNode object) Extends anMappingExpressionParser.ExprValuesContextusing the context containing the supplied object value- Parameters:
ctx- context to serve as a parent context and provide invoking stateevc- expression values context to be updatedobject- value to be added to the expression values context- Returns:
MappingExpressionParser.ExprValuesContextupdated using the context containing the supplied index value
-
addStringExprVarContext
public static MappingExpressionParser.ExprValuesContext addStringExprVarContext(MappingExpressionParser.ExprContext ctx, MappingExpressionParser.ExprValuesContext evc, String string) Extends anMappingExpressionParser.ExprValuesContextusing the context containing the supplied string value- Parameters:
ctx- context to serve as the parent of the generated contextevc- expression values contextstring- value to be added to the ExprValuesContext- Returns:
MappingExpressionParser.ExprValuesContextupdated using the context containing the supplied index value
-
fillExprVarContext
public static MappingExpressionParser.ExprValuesContext fillExprVarContext(int fctVarCount, MappingExpressionParser.ExprContext ctx, com.fasterxml.jackson.databind.JsonNode... elements) Creates anMappingExpressionParser.ExprValuesContextcontaining a parenthesized comma separated variable list of the supplied elements- Parameters:
fctVarCount- the maximum number of parameters the receiving function will acceptctx- context used to create theMappingExpressionParser.ExprValuesContextelements- the values to be added to the list- Returns:
MappingExpressionParser.ExprValuesContextcontaining a parenthesized comma separated variable list of the supplied elements
-
getArrayConstructorContext
public static MappingExpressionParser.Array_constructorContext getArrayConstructorContext(MappingExpressionParser.ExprContext ctx, com.fasterxml.jackson.databind.node.ArrayNode array) Creates anMappingExpressionParser.Array_constructorContextfrom the supplied context and array- Parameters:
ctx- context to serve as parent of generated context.array- ArrayNode whose content is used to create the Array_constructor context- Returns:
MappingExpressionParser.Array_constructorContextcreated from the supplied context and array
-
getContextVariable
public static com.fasterxml.jackson.databind.JsonNode getContextVariable(ExpressionsVisitor exprVisitor) Retrieve the latest context variable from theExpressionsVisitorstack, allowing for a null to be returned (in lieu of a NullNode)- Parameters:
exprVisitor- the expression visitor whose stack is being used- Returns:
- the latest context variable, or a NullNode if none are available.
-
getContextVariableOrNullNode
public static com.fasterxml.jackson.databind.JsonNode getContextVariableOrNullNode(ExpressionsVisitor exprVisitor) Retrieve the latest context variable from theExpressionsVisitorstack- Parameters:
exprVisitor-- Returns:
- the latest context variable, or a NullNode if none are available.
-
getObjectConstructorContext
public static MappingExpressionParser.Object_constructorContext getObjectConstructorContext(MappingExpressionParser.ExprContext ctx, com.fasterxml.jackson.databind.node.ObjectNode object) Creates anMappingExpressionParser.Object_constructorContextfrom the supplied context and object- Parameters:
ctx- ObjectConstructorContextobject- ObjectNode whose context is sought- Returns:
MappingExpressionParser.Object_constructorContextcreated from the supplied context and object
-
getValuesListExpression
public static com.fasterxml.jackson.databind.JsonNode getValuesListExpression(ExpressionsVisitor exprVisitor, MappingExpressionParser.Function_callContext ctx, int index) Gets the expression at the supplied index from the context'sMappingExpressionParser.ExprValuesContextMappingExpressionParser.ExprListContext, preserving the null value (or returning null if the index is invalid)- Parameters:
exprVisitor- used to visit the context's valuesctx- context providingMappingExpressionParser.ExprValuesContextMappingExpressionParser.ExprListContextindex- non-negative index into theMappingExpressionParser.ExprListContext- Returns:
- value of the interpretation of the index-th expression from the
context's
MappingExpressionParser.ExprValuesContextMappingExpressionParser.ExprListContext, or a NullNode if none exists
-
validateArguments
public static void validateArguments(String possibleException, ExpressionsVisitor exprVisitor, MappingExpressionParser.Function_callContext ctx, int index, String signature) Checks the expression at the supplied index from the context'sMappingExpressionParser.ExprValuesContextMappingExpressionParser.ExprListContext, preserving the null value (or returning null if the index is invalid) to determine if the arguments are valid according to the supplied signature- Parameters:
exprVisitor- used to visit the context's valuesctx- context providingMappingExpressionParser.ExprValuesContextMappingExpressionParser.ExprListContextindex- non-negative index into theMappingExpressionParser.ExprListContextsignature- the acceptable arguments signature- Throws:
EvaluateRuntimeException- if the variables do not match the signature
-
checkArgument
public static boolean checkArgument(ExpressionsVisitor exprVisitor, MappingExpressionParser.ExprContext exprCtx, String signature) Tests whether the supplied exprCtx meets the signature expectations. Note: $ or $$ references to context are not explicitly tested as they are resolved after this point. This test is for explicit variable declarations.- Parameters:
exprCtx- argument to be testedsignature- test to be performed- Returns:
- true if the argument meets the test
-
getValuesListExpressionOrNullNode
public static com.fasterxml.jackson.databind.JsonNode getValuesListExpressionOrNullNode(ExpressionsVisitor exprVisitor, MappingExpressionParser.Function_callContext ctx, int index) Gets the expression at the supplied index from the context's {link ExprValuesContext} {link ExprListContext]- Parameters:
exprVisitor- used to visit the context's valuesctx- context providingMappingExpressionParser.ExprValuesContextMappingExpressionParser.ExprListContextindex- non-negative index into theMappingExpressionParser.ExprListContext- Returns:
- value of the interpretation of the index-th expression from the
context's
MappingExpressionParser.ExprValuesContextMappingExpressionParser.ExprListContext, or a NullNode if none exists
-
processVariablesCallFunction
public static com.fasterxml.jackson.databind.JsonNode processVariablesCallFunction(ExpressionsVisitor exprVisitor, FunctionBase function, org.antlr.v4.runtime.tree.TerminalNode varid, MappingExpressionParser.Function_callContext ctx, com.fasterxml.jackson.databind.JsonNode... elements) Creates anMappingExpressionParser.ExprListContextcontaining the parenthesized comma separated variable list of JsonNode elements, sets it in the supplied context (ctx) and then executes the function to return its result.- Parameters:
exprVisitor- used to invoke the function after updating its context variablesfunction- the function to be invokedvarid- the variable to be associated with the elementsctx- the context to be updated and used by the function when invokedelements- the values to be set in theMappingExpressionParser.ExprValuesContextused by the function when invoked- Returns:
- the result of calling the function with the updated context
-
processFctCallVariables
public static com.fasterxml.jackson.databind.JsonNode processFctCallVariables(ExpressionsVisitor exprVisitor, FunctionBase function, org.antlr.v4.runtime.tree.TerminalNode varid, MappingExpressionParser.Function_callContext ctx, com.fasterxml.jackson.databind.JsonNode value, String key, com.fasterxml.jackson.databind.node.ObjectNode object) Creates anMappingExpressionParser.ExprListContextcontaining the parenthesized comma separated variable list of JsonNode elements, sets it in the supplied context (ctx) and then executes the function to return its result.- Parameters:
exprVisitor- used to invoke the function after updating its context variablesfunction- the function to be invokedvarid- the variable to be associated with the elementsctx- the context to be updated and used by the function when invokedvalue- the value to be set in theMappingExpressionParser.ExprValuesContextused by the function when invokedkey- the key to be set in theMappingExpressionParser.ExprValuesContextused by the function when invokedobject- the object to be set in theMappingExpressionParser.ExprValuesContextused by the function when invoked- Returns:
- the result of calling the function with the updated context
-
useContextVariable
public static boolean useContextVariable(FunctionBase fct, MappingExpressionParser.Function_callContext ctx, String signature) Determine if the function should use the context variable as its first parameter- Parameters:
fct- the function checking whether to use the context variablectx- the context used to invoke the functionsignature- the function signature for the function being tested. If this contains a hyphen, then it can use the context- Returns:
- true if the context variable should be used as the first parameter
-
getOptionalArgCount
-
getFunctionArgFromCtx
public static DeclaredFunction getFunctionArgFromCtx(ExpressionsVisitor expressionVisitor, MappingExpressionParser.Function_callContext ctx, boolean useContext)
-