Class FunctionUtils
- java.lang.Object
-
- com.api.jsonata4java.expressions.utils.FunctionUtils
-
- All Implemented Interfaces:
Serializable
public class FunctionUtils extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description FunctionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static MappingExpressionParser.ExprValuesContextaddArrayExprVarContext(MappingExpressionParser.ExprContext ctx, MappingExpressionParser.ExprValuesContext evc, com.fasterxml.jackson.databind.node.ArrayNode arrayNode)Extends a suppliedMappingExpressionParser.ExprValuesContextusing the supplied context and array node contentstatic MappingExpressionParser.ExprValuesContextaddIndexExprVarContext(MappingExpressionParser.ExprContext ctx, MappingExpressionParser.ExprValuesContext evc, Integer index)Extends anMappingExpressionParser.ExprValuesContextusing the context containing the supplied index valuestatic MappingExpressionParser.ExprValuesContextaddObjectExprVarContext(MappingExpressionParser.ExprContext ctx, MappingExpressionParser.ExprValuesContext evc, com.fasterxml.jackson.databind.node.ObjectNode object)Extends anMappingExpressionParser.ExprValuesContextusing the context containing the supplied object valuestatic MappingExpressionParser.ExprValuesContextaddStringExprVarContext(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.static MappingExpressionParser.ExprValuesContextfillExprVarContext(int fctVarCount, MappingExpressionParser.ExprContext ctx, com.fasterxml.jackson.databind.JsonNode... elements)Creates anMappingExpressionParser.ExprValuesContextcontaining a parenthesized comma separated variable list of the supplied elementsstatic MappingExpressionParser.ExprValuesContextfillExprVarContext(MappingExpressionParser.ExprContext ctx, String key, com.fasterxml.jackson.databind.JsonNode value)Sets up theMappingExpressionParser.ExprValuesContextvariables for the function($v,$k) signature used in each call for pairs of values and keysstatic MappingExpressionParser.Array_constructorContextgetArrayConstructorContext(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 MappingExpressionParser.Object_constructorContextgetObjectConstructorContext(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, Function 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, Function 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(Function 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
-
-
-
Method Detail
-
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
-
fillExprVarContext
public static MappingExpressionParser.ExprValuesContext fillExprVarContext(MappingExpressionParser.ExprContext ctx, String key, com.fasterxml.jackson.databind.JsonNode value)
Sets up theMappingExpressionParser.ExprValuesContextvariables for the function($v,$k) signature used in each call for pairs of values and keys- Parameters:
ctx- context to be used to create the newMappingExpressionParser.ExprListContextto contain the key, value pairkey- key used to relate the supplied value in the ExprValuesContextvalue- content to be added to the ExprValuesContext- Returns:
MappingExpressionParser.ExprValuesContextcontaining the key and value in its parenthesized comma separated variableMappingExpressionParser.ExprListContext
-
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, Function 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, Function 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(Function 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
public static int getOptionalArgCount(String signature)
-
-