Class JexlArrayBuilder

java.lang.Object
net.simplace.core.jexl.builder.JexlArrayBuilder

public final class JexlArrayBuilder extends Object
Array functions for JEXL rules (namespace array:), used like
array:Double(size, default)
array:Integer(size, default)
array:Char(size, default)
array:Double(size)
array:Integer(size)
array:Char(size)
array:clone(sourceArray)
array:zip(keyArray, valueArray)
array:unzipKeys(sourceArray)
array:unzipValues(sourceArray)
array:calc(sourceArray, algorithm[+-*\/^] secondPartner)
array:sum(sourceArray)
array:avg(sourceArray)
array:min(sourceArray)
array:max(sourceArray)
array:sum(sourceArray, startIndex[1...n], endIndex[1...n])
array:avg(sourceArray, startIndex[1...n], endIndex[1...n])
array:min(sourceArray, startIndex[1...n], endIndex[1...n])
array:max(sourceArray, startIndex[1...n], endIndex[1...n])
array:progressivesum(sourceArray)
Numeric functions support Double[] and Integer[] arrays.
Author:
Andreas Enders
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    avg(Object anArray)
    Used in JEXL like array:avg(sourceArray).
    static Object
    avg(Object anArray, Integer aStartIndex, Integer aEndIndex)
    Used in JEXL like array:avg(sourceArray, startIndex, endIndex): the mean of a range; the range is limited to the array, the sum is divided by the number of elements actually used (Integer[]: truncated).
    static Object
    calc(Object aFirstArray, String aRule, Object aSecondPartner)
    Used in JEXL like array:calc(firstArray, '*', secondPartner): applies an operator element-wise.
    static String[]
    Char(int aSize)
    Used in JEXL like array:Char(size).
    static String[]
    Char(int aSize, String aDefault)
    Used in JEXL like array:Char(size, default).
    static Object
    clone(Object aSourceArray)
    Used in JEXL like array:clone(sourceArray).
    static Double[]
    Double(int aSize)
    Used in JEXL like array:Double(size).
    static Double[]
    Double(int aSize, Double aDefault)
    Used in JEXL like array:Double(size, default).
    static Integer[]
    Integer(int aSize)
    Used in JEXL like array:Integer(size).
    static Integer[]
    Integer(int aSize, Integer aDefault)
    Used in JEXL like array:Integer(size, default).
    static Object
    max(Object anArray)
    Used in JEXL like array:max(sourceArray).
    static Object
    max(Object anArray, Integer aStartIndex, Integer aEndIndex)
    Used in JEXL like array:max(sourceArray, startIndex, endIndex): the maximum of a range; the range is limited to the array.
    static Object
    min(Object anArray)
    Used in JEXL like array:min(sourceArray).
    static Object
    min(Object anArray, Integer aStartIndex, Integer aEndIndex)
    Used in JEXL like array:min(sourceArray, startIndex, endIndex): the minimum of a range; the range is limited to the array.
    static Object
    Used in JEXL like array:progressivesum(sourceArray): cumulative sum.
    static Object
    sum(Object anArray)
    Used in JEXL like array:sum(sourceArray).
    static Object
    sum(Object anArray, Integer aStartIndex, Integer aEndIndex)
    Used in JEXL like array:sum(sourceArray, startIndex, endIndex): the sum of a range; the range is limited to the array.
    static Object
    unzipKeys(Object aSourceArray)
    Used in JEXL like array:unzipKeys(sourceArray); the inverse of zip(Object[], Object[]).
    static Object
    unzipValues(Object aSourceArray)
    Used in JEXL like array:unzipValues(sourceArray); the inverse of zip(Object[], Object[]).
    static Object
    zip(Object[] aKeysSourceArray, Object[] aValuesSourceArray)
    Used in JEXL like array:zip(keyArray, valueArray): merges two arrays of the same type alternately.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JexlArrayBuilder

      public JexlArrayBuilder()
  • Method Details

    • clone

      public static Object clone(Object aSourceArray)
      Used in JEXL like array:clone(sourceArray).
      Parameters:
      aSourceArray - a String[], Double[] or Integer[] array
      Returns:
      a shallow copy of the array (same type and size), or null for other types
    • Double

      public static Double[] Double(int aSize)
      Used in JEXL like array:Double(size).
      Parameters:
      aSize - length of the array
      Returns:
      a new Double[] filled with null
    • Integer

      public static Integer[] Integer(int aSize)
      Used in JEXL like array:Integer(size).
      Parameters:
      aSize - length of the array
      Returns:
      a new Integer[] filled with null
    • Char

      public static String[] Char(int aSize)
      Used in JEXL like array:Char(size).
      Parameters:
      aSize - length of the array
      Returns:
      a new String[] filled with null
    • Double

      public static Double[] Double(int aSize, Double aDefault)
      Used in JEXL like array:Double(size, default).
      Parameters:
      aSize - length of the array
      aDefault - value of all elements
      Returns:
      a new Double[] filled with the default
    • Integer

      public static Integer[] Integer(int aSize, Integer aDefault)
      Used in JEXL like array:Integer(size, default).
      Parameters:
      aSize - length of the array
      aDefault - value of all elements
      Returns:
      a new Integer[] filled with the default
    • Char

      public static String[] Char(int aSize, String aDefault)
      Used in JEXL like array:Char(size, default).
      Parameters:
      aSize - length of the array
      aDefault - value of all elements
      Returns:
      a new String[] filled with the default
    • unzipKeys

      public static Object unzipKeys(Object aSourceArray)
      Used in JEXL like array:unzipKeys(sourceArray); the inverse of zip(Object[], Object[]).
      Parameters:
      aSourceArray - a zipped Double[], Integer[] or String[] array {key1, value1, key2, value2, ...}
      Returns:
      the keys (elements with even index), or null for other types (a warning is logged)
    • unzipValues

      public static Object unzipValues(Object aSourceArray)
      Used in JEXL like array:unzipValues(sourceArray); the inverse of zip(Object[], Object[]).
      Parameters:
      aSourceArray - a zipped Double[], Integer[] or String[] array {key1, value1, key2, value2, ...}
      Returns:
      the values (elements with odd index), or null for other types (a warning is logged)
    • zip

      public static Object zip(Object[] aKeysSourceArray, Object[] aValuesSourceArray)
      Used in JEXL like array:zip(keyArray, valueArray): merges two arrays of the same type alternately.
      Parameters:
      aKeysSourceArray - the keys (Double[], Integer[] or String[])
      aValuesSourceArray - the values, same type and at least as long as the keys
      Returns:
      {key1, value1, key2, value2, ...}, or null for other or mixed types (a warning is logged)
    • calc

      public static Object calc(Object aFirstArray, String aRule, Object aSecondPartner)
      Used in JEXL like array:calc(firstArray, '*', secondPartner): applies an operator element-wise. Errors (also an unknown operator) are logged; elements not yet calculated then keep their original value.
      Parameters:
      aFirstArray - a Double[] or Integer[] array (not changed)
      aRule - the operator: *, +, -, / or ^ (for Integer[] the power is truncated to int)
      aSecondPartner - an array of the same type (element-wise) or a single number of the same type
      Returns:
      a new array (same type and size) with the results, or null for other types
    • sum

      public static Object sum(Object anArray)
      Used in JEXL like array:sum(sourceArray).
      Parameters:
      anArray - a Double[] or Integer[] array
      Returns:
      the sum of all elements, or null for other types
    • progressivesum

      public static Object progressivesum(Object anArray)
      Used in JEXL like array:progressivesum(sourceArray): cumulative sum.
      Parameters:
      anArray - a Double[] or Integer[] array (not changed)
      Returns:
      a new array, each element increased by the sum of all previous elements, or null for other types
    • min

      public static Object min(Object anArray)
      Used in JEXL like array:min(sourceArray).
      Parameters:
      anArray - a Double[] or Integer[] array
      Returns:
      the minimum of all elements, or null for other types
    • max

      public static Object max(Object anArray)
      Used in JEXL like array:max(sourceArray).
      Parameters:
      anArray - a Double[] or Integer[] array
      Returns:
      the maximum of all elements, or null for other types
    • avg

      public static Object avg(Object anArray)
      Used in JEXL like array:avg(sourceArray).
      Parameters:
      anArray - a Double[] or Integer[] array
      Returns:
      the mean of all elements (truncated for Integer[]), or null for other types
    • sum

      public static Object sum(Object anArray, Integer aStartIndex, Integer aEndIndex)
      Used in JEXL like array:sum(sourceArray, startIndex, endIndex): the sum of a range; the range is limited to the array.
      Parameters:
      anArray - a Double[] or Integer[] array
      aStartIndex - first element (1-based, inclusive)
      aEndIndex - last element (1-based, inclusive)
      Returns:
      the sum of the range, or null for other types
    • min

      public static Object min(Object anArray, Integer aStartIndex, Integer aEndIndex)
      Used in JEXL like array:min(sourceArray, startIndex, endIndex): the minimum of a range; the range is limited to the array.
      Parameters:
      anArray - a Double[] or Integer[] array
      aStartIndex - first element (1-based, inclusive)
      aEndIndex - last element (1-based, inclusive)
      Returns:
      the minimum of the range, or null for other types
    • max

      public static Object max(Object anArray, Integer aStartIndex, Integer aEndIndex)
      Used in JEXL like array:max(sourceArray, startIndex, endIndex): the maximum of a range; the range is limited to the array.
      Parameters:
      anArray - a Double[] or Integer[] array
      aStartIndex - first element (1-based, inclusive)
      aEndIndex - last element (1-based, inclusive)
      Returns:
      the maximum of the range, or null for other types
    • avg

      public static Object avg(Object anArray, Integer aStartIndex, Integer aEndIndex)
      Used in JEXL like array:avg(sourceArray, startIndex, endIndex): the mean of a range; the range is limited to the array, the sum is divided by the number of elements actually used (Integer[]: truncated).
      Parameters:
      anArray - a Double[] or Integer[] array
      aStartIndex - first element (1-based, inclusive)
      aEndIndex - last element (1-based, inclusive)
      Returns:
      the mean of the range, or null for other types