Package glide.utils

Class ArrayTransformUtils


  • public class ArrayTransformUtils
    extends java.lang.Object
    Utility methods for data conversion.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T,​U extends T>
      U[][][]
      cast3DArray​(T[] outerObjectArr, java.lang.Class<U> clazz)
      Casts an Object[][][] to T[][][] by casting each nested array and every array element.
      static <T,​U extends T>
      U[]
      castArray​(T[] objectArr, java.lang.Class<U> clazz)
      Casts an array of objects to an array of type T.
      static <T,​U extends T>
      U[][]
      castArrayofArrays​(T[] outerObjectArr, java.lang.Class<U> clazz)
      Casts an Object[][] to T[][] by casting each nested array and every array element.
      static <T> java.util.Map<GlideString,​T[]> castBinaryStringMapOfArrays​(java.util.Map<GlideString,​java.lang.Object[]> mapOfArrays, java.lang.Class<T> clazz)
      Maps a Map of Arrays with value type T[] to value of U[].
      static <S,​T>
      java.util.Map<S,​T[][]>
      castMapOf2DArray​(java.util.Map<S,​java.lang.Object[][]> mapOfArrays, java.lang.Class<T> clazz)
      Maps a Map of Object[][] with value type T[][] to value of U[][].
      static <T> java.util.Map<java.lang.String,​T[]> castMapOfArrays​(java.util.Map<java.lang.String,​java.lang.Object[]> mapOfArrays, java.lang.Class<T> clazz)
      Maps a Map of Arrays with value type T[] to value of U[].
      static <T> T[] concatenateArrays​(T[]... arrays)
      Concatenates multiple arrays of type T and returns a single concatenated array.
      static <U> java.util.Map<GlideString,​java.lang.Object> convertBinaryStringKeyValueArrayToMap​(java.lang.Object[] outerObjectArr, java.lang.Class<U> clazz)
      Processes a two-element array where the first element is used as a key and the second element is a Map where its values are cast to type U.
      static <U> java.util.Map<java.lang.String,​java.lang.Object> convertKeyValueArrayToMap​(java.lang.Object[] outerObjectArr, java.lang.Class<U> clazz)
      Processes a two-element array where the first element is used as a key and the second element is a Map where its values are cast to type U.
      static java.util.Map<GlideString,​GlideString> convertMapToGlideStringMap​(java.util.Map<?,​?> inputMap)
      Given an inputMap of any key / value pairs, create a new Map of
      static GlideString[] convertMapToKeyValueGlideStringArray​(java.util.Map<GlideString,​GlideString> args)
      Converts a map of GlideString keys and values to an array of GlideStrings.
      static java.lang.String[] convertMapToKeyValueStringArray​(java.util.Map<java.lang.String,​?> args)
      Converts a map of string keys and values of any type that can be converted in to an array of strings with alternating keys and values.
      static java.lang.String[] convertMapToValueKeyStringArray​(java.util.Map<java.lang.String,​java.lang.Double> args)
      Converts a map of string keys and values of any type into an array of strings with alternating values and keys.
      static GlideString[] convertMapToValueKeyStringArrayBinary​(java.util.Map<GlideString,​java.lang.Double> args)
      Converts a map of GlideString keys and values of any type into an array of GlideStrings with alternating values and keys.
      static GlideString[] convertNestedArrayToKeyValueGlideStringArray​(GlideString[][] args)
      Converts a nested array of GlideString keys and values in to an array of GlideStrings with alternating keys and values.
      static java.lang.String[] convertNestedArrayToKeyValueStringArray​(java.lang.String[][] args)
      Converts a nested array of string keys and values of any type that can be converted in to an array of strings with alternating keys and values.
      static GlideString[] flattenAllKeysFollowedByAllValues​(java.util.Map<?,​?> args)
      Converts a map of any type of keys and values in to an array of GlideString where all keys are placed first, followed by the values.
      static GlideString[] flattenMapToGlideStringArray​(java.util.Map<?,​?> args)
      Converts a map of any type of keys and values in to an array of GlideString with alternating keys and values.
      static GlideString[] flattenMapToGlideStringArrayValueFirst​(java.util.Map<?,​?> args)
      Converts a map of any type of keys and values in to an array of GlideString with alternating values and keys.
      static <T> GlideString[] flattenNestedArrayToGlideStringArray​(T[][] args)
      Converts a nested array of any type of keys and values in to an array of GlideString with alternating keys and values.
      static java.lang.String[] mapGeoDataToArray​(java.util.Map<java.lang.String,​GeospatialData> args)
      Converts a geospatial members to geospatial data mapping in to an array of arguments in the form of [Longitude, Latitude, Member ...].
      static <ArgType> GlideString[] mapGeoDataToGlideStringArray​(java.util.Map<ArgType,​GeospatialData> args)
      Converts a geospatial members to geospatial data mapping in to an array of arguments in the form of [Longitude, Latitude, Member ...].
      static <ArgType> GlideString[] toGlideStringArray​(ArgType[] args)
      Converts any array into GlideString array keys and values.
      • Methods inherited from class java.lang.Object

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

      • ArrayTransformUtils

        public ArrayTransformUtils()
    • Method Detail

      • convertMapToKeyValueStringArray

        public static java.lang.String[] convertMapToKeyValueStringArray​(java.util.Map<java.lang.String,​?> args)
        Converts a map of string keys and values of any type that can be converted in to an array of strings with alternating keys and values.
        Parameters:
        args - Map of string keys to values of any type to convert.
        Returns:
        Array of strings [key1, value1.toString(), key2, value2.toString(), ...].
      • convertMapToKeyValueGlideStringArray

        public static GlideString[] convertMapToKeyValueGlideStringArray​(java.util.Map<GlideString,​GlideString> args)
        Converts a map of GlideString keys and values to an array of GlideStrings.
        Parameters:
        args - Map of GlideString keys to values of GlideString.
        Returns:
        Array of strings [key1, gs(value1.toString()), key2, gs(value2.toString()), ...].
      • convertNestedArrayToKeyValueStringArray

        public static java.lang.String[] convertNestedArrayToKeyValueStringArray​(java.lang.String[][] args)
        Converts a nested array of string keys and values of any type that can be converted in to an array of strings with alternating keys and values.
        Parameters:
        args - Nested array of string keys to values of any type to convert.
        Returns:
        Array of strings [key1, value1.toString(), key2, value2.toString(), ...].
      • convertNestedArrayToKeyValueGlideStringArray

        public static GlideString[] convertNestedArrayToKeyValueGlideStringArray​(GlideString[][] args)
        Converts a nested array of GlideString keys and values in to an array of GlideStrings with alternating keys and values.
        Parameters:
        args - Nested array of GlideString keys and values to convert.
        Returns:
        Array of strings [key1, gs(value1.toString()), key2, gs(value2.toString()), ...].
      • convertMapToValueKeyStringArray

        public static java.lang.String[] convertMapToValueKeyStringArray​(java.util.Map<java.lang.String,​java.lang.Double> args)
        Converts a map of string keys and values of any type into an array of strings with alternating values and keys.
        Parameters:
        args - Map of string keys to values of Double type to convert.
        Returns:
        Array of strings [value1.toString(), key1, value2.toString(), key2, ...].
      • convertMapToValueKeyStringArrayBinary

        public static GlideString[] convertMapToValueKeyStringArrayBinary​(java.util.Map<GlideString,​java.lang.Double> args)
        Converts a map of GlideString keys and values of any type into an array of GlideStrings with alternating values and keys.
        Parameters:
        args - Map of GlideString keys to values of Double type to convert.
        Returns:
        Array of GlideStrings [gs(value1.toString()), key1, gs(value2.toString()), key2, ...].
      • castArray

        public static <T,​U extends T> U[] castArray​(T[] objectArr,
                                                          java.lang.Class<U> clazz)
        Casts an array of objects to an array of type T.
        Type Parameters:
        T - The base type from which the elements are being cast.
        U - The subtype of T to which the elements are cast.
        Parameters:
        objectArr - Array of objects to cast.
        clazz - The class of the array elements to cast to.
        Returns:
        An array of type U, containing the elements from the input array.
      • castArrayofArrays

        public static <T,​U extends T> U[][] castArrayofArrays​(T[] outerObjectArr,
                                                                    java.lang.Class<U> clazz)
        Casts an Object[][] to T[][] by casting each nested array and every array element.
        Type Parameters:
        T - The base type from which the elements are being cast.
        U - The subtype of T to which the elements are cast.
        Parameters:
        outerObjectArr - Array of arrays of objects to cast.
        clazz - The class of the array elements to cast to.
        Returns:
        An array of arrays of type U, containing the elements from the input array.
      • convertKeyValueArrayToMap

        public static <U> java.util.Map<java.lang.String,​java.lang.Object> convertKeyValueArrayToMap​(java.lang.Object[] outerObjectArr,
                                                                                                           java.lang.Class<U> clazz)
        Processes a two-element array where the first element is used as a key and the second element is a Map where its values are cast to type U.
        Type Parameters:
        U - The type to which the elements are cast.
        Parameters:
        outerObjectArr - A two-element array with array[0] as the key, array[1] as the value/map.
        clazz - The class to which values should be cast.
        Returns:
        A Map with a single entry with the first element as the key, and the second element is the value of type Map
      • convertBinaryStringKeyValueArrayToMap

        public static <U> java.util.Map<GlideString,​java.lang.Object> convertBinaryStringKeyValueArrayToMap​(java.lang.Object[] outerObjectArr,
                                                                                                                  java.lang.Class<U> clazz)
        Processes a two-element array where the first element is used as a key and the second element is a Map where its values are cast to type U.
        Type Parameters:
        U - The type to which the elements are cast.
        Parameters:
        outerObjectArr - A two-element array with array[0] as the key, array[1] as the value/map.
        clazz - The class to which values should be cast.
        Returns:
        A Map with a single entry with the first element as the key, and the second element is the value of type Map
      • cast3DArray

        public static <T,​U extends T> U[][][] cast3DArray​(T[] outerObjectArr,
                                                                java.lang.Class<U> clazz)
        Casts an Object[][][] to T[][][] by casting each nested array and every array element.
        Type Parameters:
        T - The base type from which the elements are being cast.
        U - The subtype of T to which the elements are cast.
        Parameters:
        outerObjectArr - 3D array of objects to cast.
        clazz - The class of the array elements to cast to.
        Returns:
        An array of arrays of type U, containing the elements from the input array.
      • castMapOfArrays

        public static <T> java.util.Map<java.lang.String,​T[]> castMapOfArrays​(java.util.Map<java.lang.String,​java.lang.Object[]> mapOfArrays,
                                                                                    java.lang.Class<T> clazz)
        Maps a Map of Arrays with value type T[] to value of U[].
        Type Parameters:
        T - The target type which the elements are cast.
        Parameters:
        mapOfArrays - Map of Array values to cast.
        clazz - The class of the array values to cast to.
        Returns:
        A Map of arrays of type U[], containing the key/values from the input Map.
      • castBinaryStringMapOfArrays

        public static <T> java.util.Map<GlideString,​T[]> castBinaryStringMapOfArrays​(java.util.Map<GlideString,​java.lang.Object[]> mapOfArrays,
                                                                                           java.lang.Class<T> clazz)
        Maps a Map of Arrays with value type T[] to value of U[].
        Type Parameters:
        T - The target type which the elements are cast.
        Parameters:
        mapOfArrays - Map of Array values to cast.
        clazz - The class of the array values to cast to.
        Returns:
        A Map of arrays of type U[], containing the key/values from the input Map.
      • castMapOf2DArray

        public static <S,​T> java.util.Map<S,​T[][]> castMapOf2DArray​(java.util.Map<S,​java.lang.Object[][]> mapOfArrays,
                                                                                java.lang.Class<T> clazz)
        Maps a Map of Object[][] with value type T[][] to value of U[][].
        Type Parameters:
        T - The target type which the elements are cast.
        S - String type, could be either String or GlideString.
        Parameters:
        mapOfArrays - Map of 2D Array values to cast.
        clazz - The class of the array values to cast to.
        Returns:
        A Map of arrays of type U[][], containing the key/values from the input Map.
      • concatenateArrays

        @SafeVarargs
        public static <T> T[] concatenateArrays​(T[]... arrays)
        Concatenates multiple arrays of type T and returns a single concatenated array.
        Type Parameters:
        T - The type of the elements in the arrays.
        Parameters:
        arrays - Varargs parameter for arrays to be concatenated.
        Returns:
        A concatenated array of type T.
      • flattenMapToGlideStringArray

        public static GlideString[] flattenMapToGlideStringArray​(java.util.Map<?,​?> args)
        Converts a map of any type of keys and values in to an array of GlideString with alternating keys and values.
        Parameters:
        args - Map of keys to values of any type to convert.
        Returns:
        Array of GlideString [key1, value1, key2, value2, ...].
      • flattenNestedArrayToGlideStringArray

        public static <T> GlideString[] flattenNestedArrayToGlideStringArray​(T[][] args)
        Converts a nested array of any type of keys and values in to an array of GlideString with alternating keys and values.
        Parameters:
        args - Nested array of keys to values of any type to convert.
        Returns:
        Array of GlideString [key1, value1, key2, value2, ...].
      • flattenMapToGlideStringArrayValueFirst

        public static GlideString[] flattenMapToGlideStringArrayValueFirst​(java.util.Map<?,​?> args)
        Converts a map of any type of keys and values in to an array of GlideString with alternating values and keys.

        This method is similar to flattenMapToGlideStringArray, but it places the value before the key

        Parameters:
        args - Map of keys to values of any type to convert.
        Returns:
        Array of GlideString [value1, key1, value2, key2...].
      • flattenAllKeysFollowedByAllValues

        public static GlideString[] flattenAllKeysFollowedByAllValues​(java.util.Map<?,​?> args)
        Converts a map of any type of keys and values in to an array of GlideString where all keys are placed first, followed by the values.
        Parameters:
        args - Map of keys to values of any type to convert.
        Returns:
        Array of GlideString [key1, key2, value1, value2...].
      • toGlideStringArray

        public static <ArgType> GlideString[] toGlideStringArray​(ArgType[] args)
        Converts any array into GlideString array keys and values.
        Parameters:
        args - Map of keys to values of any type to convert.
        Returns:
        Array of strings [key1, value1, key2, value2, ...].
      • convertMapToGlideStringMap

        public static java.util.Map<GlideString,​GlideString> convertMapToGlideStringMap​(java.util.Map<?,​?> inputMap)
        Given an inputMap of any key / value pairs, create a new Map of
        Parameters:
        inputMap - Map of values to convert.
        Returns:
        A Map of