Class Functions

java.lang.Object
com.dashjoin.jsonata.Functions

public class Functions extends Object
  • Constructor Details

    • Functions

      public Functions()
  • Method Details

    • sum

      public static Number sum(List<Number> args)
      Sum function
    • count

      public static Number count(List<Object> args)
      Count function
    • max

      public static Number max(List<Number> args)
      Max function
    • min

      public static Number min(List<Number> args)
      Min function
    • average

      public static Number average(List<Number> args)
      Average function
    • string

      public static String string(Object arg, Boolean prettify)
      Stringify arguments
    • validateInput

      public static void validateInput(Object arg)
      Validate input data types. This will make sure that all input data can be processed.
      Parameters:
      arg -
    • substring

      public static String substring(String str, Number _start, Number _length)
      Create substring based on character number and length
    • substr

      public static String substr(String str, Integer start, Integer length)
      Source = Jsonata4Java JSONataUtils.substr
      Parameters:
      str -
      start - Location at which to begin extracting characters. If a negative number is given, it is treated as strLength - start where strLength is the length of the string. For example, str.substr(-3) is treated as str.substr(str.length - 3)
      length - The number of characters to extract. If this argument is null, all the characters from start to the end of the string are extracted.
      Returns:
      A new string containing the extracted section of the given string. If length is 0 or a negative number, an empty string is returned.
    • substringBefore

      public static String substringBefore(String str, String chars)
      Create substring up until a character
    • substringAfter

      public static String substringAfter(String str, String chars)
      Create substring after a character
    • lowercase

      public static String lowercase(String str)
      Lowercase a string
    • uppercase

      public static String uppercase(String str)
      Uppercase a string
    • length

      public static Integer length(String str)
      length of a string
    • trim

      public static String trim(String str)
      Normalize and trim whitespace within a string
    • pad

      public static String pad(String str, Integer width, String _char)
      Pad a string to a minimum width by adding characters to the start or end
    • leftPad

      public static String leftPad(String str, int size, String padStr)
    • rightPad

      public static String rightPad(String str, int size, String padStr)
    • evaluateMatcher

      public static List<com.dashjoin.jsonata.Functions.RegexpMatch> evaluateMatcher(Pattern matcher, String str)
      Evaluate the matcher function against the str arg
    • contains

      public static Boolean contains(String str, Object token)
      Tests if the str contains the token
    • match

      public static List<Map> match(String str, Pattern regex, Integer limit)
      Match a string with a regex returning an array of object containing details of each match
    • join

      public static String join(List<String> strs, String separator)
      Join an array of strings
    • replace

      public static String replace(String str, Object pattern, Object replacement, Integer limit)
    • base64encode

      public static String base64encode(String str)
      Base64 encode a string
    • base64decode

      public static String base64decode(String str)
      Base64 decode a string
    • encodeUrlComponent

      public static String encodeUrlComponent(String str)
      Encode a string into a component for a url
    • encodeUrl

      public static String encodeUrl(String str)
      Encode a string into a url
    • decodeUrlComponent

      public static String decodeUrlComponent(String str)
      Decode a string from a component for a url
    • decodeUrl

      public static String decodeUrl(String str)
      Decode a string from a url
    • split

      public static List<String> split(String str, Object pattern, Number limit)
    • formatNumber

      public static String formatNumber(Number value, String picture, Map options)
      Formats a number into a decimal string representation using XPath 3.1 Finvalid input: '&O' fn:format-number spec
    • formatBase

      public static String formatBase(Number value, Number _radix)
      Converts a number to a string using a specified number base
    • number

      public static Number number(Object arg) throws NumberFormatException, JException
      Cast argument to number
      Throws:
      NumberFormatException
      JException
    • abs

      public static Number abs(Number arg)
      Absolute value of a number
    • floor

      public static Number floor(Number arg)
      Rounds a number down to integer
    • ceil

      public static Number ceil(Number arg)
      Rounds a number up to integer
    • round

      public static Number round(Number arg, Number precision)
      Round to half even
    • sqrt

      public static Number sqrt(Number arg)
      Square root of number
    • power

      public static Number power(Number arg, Number exp)
      Raises number to the power of the second number
    • random

      public static Number random()
      Returns a random number 0 invalid input: '<'= n invalid input: '<' 1
    • toBoolean

      public static Boolean toBoolean(Object arg)
      Evaluate an input and return a boolean
    • not

      public static Boolean not(Object arg)
      returns the Boolean NOT of the arg
    • getFunctionArity

      public static int getFunctionArity(Object func)
    • hofFuncArgs

      public static List hofFuncArgs(Object func, Object arg1, Object arg2, Object arg3)
      Helper function to build the arguments to be supplied to the function arg of the HOFs map, filter, each, sift and single
    • funcApply

      public static Object funcApply(Object func, List funcArgs) throws Throwable
      Call helper for Java
      Parameters:
      func -
      funcArgs -
      Returns:
      Throws:
      Throwable
    • map

      public static List map(List arr, Object func) throws Throwable
      Create a map from an array of arguments
      Throws:
      Throwable
    • filter

      public static List filter(List arr, Object func) throws Throwable
      Create a map from an array of arguments
      Throws:
      Throwable
    • single

      public static Object single(List arr, Object func) throws Throwable
      Given an array, find the single element matching a specified condition Throws an exception if the number of matching elements is not exactly one
      Throws:
      Throwable
    • zip

      public static List zip(Utils.JList<List> args)
      Convolves (zips) each value from a set of arrays
    • foldLeft

      public static Object foldLeft(List sequence, Object func, Object init) throws Throwable
      Fold left function
      Throws:
      Throwable
    • keys

      public static List keys(Object arg)
      Return keys for an object
    • exists

      public static boolean exists(Object arg)
      Determines if the argument is undefined
    • spread

      public static Object spread(Object arg)
      Splits an object into an array of object with one property each
    • merge

      public static Object merge(List arg)
      Merges an array of objects into a single object. Duplicate properties are overridden by entries later in the array
    • reverse

      public static List reverse(List arr)
      Reverses the order of items in an array
    • each

      public static List each(Map obj, Object func) throws Throwable
      Throws:
      Throwable
    • error

      public static void error(String message) throws Throwable
    • assertFn

      public static void assertFn(boolean condition, String message) throws Throwable
    • type

      public static String type(Object value)
    • sort

      public static List sort(List arr, Object comparator)
      Implements the merge sort (stable) with optional comparator function
    • shuffle

      public static List shuffle(List arr)
      Randomly shuffles the contents of an array
    • distinct

      public static Object distinct(Object _arr)
      Returns the values that appear in a sequence, with duplicates eliminated.
    • sift

      public static Object sift(Map<Object,Object> arg, Object func) throws Throwable
      Applies a predicate function to each key/value pair in an object, and returns an object containing only the key/value pairs that passed the predicate
      Throws:
      Throwable
    • append

      public static Object append(Object arg1, Object arg2)
      Append second argument to first
    • isLambda

      public static boolean isLambda(Object result)
    • lookup

      public static Object lookup(Object input, String key)
      Return value from an object for a given key
    • test

      public static String test(String a, String b)
    • getFunction

      public static Method getFunction(Class clz, String name)
    • call

      public static Object call(Class clz, Object instance, String name, List<Object> args) throws Throwable
      Throws:
      Throwable
    • call

      public static Object call(Object instance, Method m, List<Object> args) throws Throwable
      Throws:
      Throwable
    • dateTimeToMillis

      public static Long dateTimeToMillis(String timestamp, String picture) throws ParseException
      Converts an ISO 8601 timestamp to milliseconds since the epoch
      Throws:
      ParseException
    • isNumeric

      public static boolean isNumeric(CharSequence cs)
    • dateTimeFromMillis

      public static String dateTimeFromMillis(Number millis, String picture, String timezone)
      Converts milliseconds since the epoch to an ISO 8601 timestamp
    • formatInteger

      public static String formatInteger(Number value, String picture)
      Formats an integer as specified by the XPath fn:format-integer function See https://www.w3.org/TR/xpath-functions-31/#func-format-integer
    • parseInteger

      public static Number parseInteger(String value, String picture) throws ParseException, JException
      parse a string containing an integer as specified by the picture string
      Throws:
      ParseException
      JException
    • functionClone

      public static Object functionClone(Object arg)
      Clones an object
    • functionEval

      public static Object functionEval(String expr, Object focus)
      parses and evaluates the supplied expression
    • now

      public static String now(String picture, String timezone)
    • millis

      public static long millis()