Class ArrayConversion


  • public final class ArrayConversion
    extends Object
    Provides: - methods to convert arrays of primitive types to corresponding arrays of Object types - conversion to/from Set
    • Method Detail

      • toAppropriateType

        public static Object[] toAppropriateType​(Object array)
        Convert an an array of primitive types to an array of Objects of non-primitive types eg int to Integer.
        Parameters:
        array - the array to convert
      • toBooleans

        public static Boolean[] toBooleans​(boolean[] array)
      • toCharacters

        public static Character[] toCharacters​(char[] array)
      • toBytes

        public static Byte[] toBytes​(byte[] array)
      • toShorts

        public static Short[] toShorts​(short[] array)
      • toIntegers

        public static Integer[] toIntegers​(int[] array)
      • toLongs

        public static Long[] toLongs​(long[] array)
      • toFloats

        public static Float[] toFloats​(float[] array)
      • toDoubles

        public static Double[] toDoubles​(double[] array)
      • createObjectArrayType

        public static Object[] createObjectArrayType​(Class elementType,
                                                     int size)
        Create an array whose type is elementType[] of specified size.
        Parameters:
        elementType - the type of each entry of the array
        size - the number of elements
      • subArray

        public static Object[] subArray​(Object[] in,
                                        int start,
                                        int end)
      • toSet

        public static <T> Set<T> toSet​(T[] array)
      • hasIdenticalElementClasses

        public static boolean hasIdenticalElementClasses​(Object[] a)
      • specializeArray

        public static Object[] specializeArray​(Object[] a)
        Specialize the type of the array (if possible). For example, if the array is an Object[] of Integer, return an Integer[] of Integer.
        Parameters:
        a - the array to specialize
        Returns:
        a specialized array (if possible) otherwise the original array
      • setToArray

        public static Object[] setToArray​(Set<?> s,
                                          boolean specialize)
        Convert a Set to an array. If specialize is true, then provide the most specialized type possible via specializeArray()
        Parameters:
        s - the Set to convert
        specialize - decide whether to specialize the type or not
      • setToArray

        public static Object[] setToArray​(Set<?> s)
        Convert a Set to an Object[].
        Parameters:
        s - the Set to convert
      • setToArray

        public static Object[] setToArray​(Set<?> s,
                                          Object[] out)
        Convert a Set to an Object[].
        Parameters:
        s - the Set to convert
        out - the output array, must be of size s.size()
      • arrayToSet

        public static <T> Set<T> arrayToSet​(T[] names)