Package com.gengoai

Class Primitives


  • public final class Primitives
    extends Object

    Methods for working with primitive values including wrapping, unwrapping to object types and converting collections.

    Author:
    David B. Bracewell
    • Method Detail

      • defaultValue

        public static <T> T defaultValue​(@NonNull
                                         @NonNull Class<T> clazz)
        Gets the default value of the given class (primitive and boxed versions all other classes will result in null)
        Type Parameters:
        T - the type parameter
        Parameters:
        clazz - the clazz
        Returns:
        the default value (null for non-primitives and their boxed types)
      • toByteArray

        public static byte[] toByteArray​(@NonNull
                                         @NonNull Iterable<? extends Number> numbers)
        Converts and iterable of numbers to an array of byte
        Parameters:
        numbers - the numbers to convert
        Returns:
        the byte array
      • toCharArray

        public static char[] toCharArray​(@NonNull
                                         @NonNull Iterable<Character> characters)
        Converts and iterable of Character to an array of char
        Parameters:
        characters - the characters to convert
        Returns:
        the char array
      • toDoubleArray

        public static double[] toDoubleArray​(@NonNull
                                             @NonNull Iterable<? extends Number> numbers)
        Converts and iterable of numbers to an array of double
        Parameters:
        numbers - the numbers to convert
        Returns:
        the double array
      • toFloatArray

        public static float[] toFloatArray​(@NonNull
                                           @NonNull Iterable<? extends Number> numbers)
        Converts and iterable of numbers to an array of float
        Parameters:
        numbers - the numbers to convert
        Returns:
        the float array
      • toIntArray

        public static int[] toIntArray​(@NonNull
                                       @NonNull Iterable<? extends Number> numbers)
        Converts and iterable of numbers to an array of int
        Parameters:
        numbers - the numbers to convert
        Returns:
        the int array
      • toLongArray

        public static long[] toLongArray​(@NonNull
                                         @NonNull Iterable<? extends Number> numbers)
        Converts and iterable of numbers to an array of long
        Parameters:
        numbers - the numbers to convert
        Returns:
        the long array
      • toShortArray

        public static short[] toShortArray​(@NonNull
                                           @NonNull Iterable<? extends Number> numbers)
        Converts and iterable of numbers to an array of short
        Parameters:
        numbers - the numbers to convert
        Returns:
        the short array
      • unwrap

        public static <T> Class<T> unwrap​(Class<T> type)
        Gets the primitive type class corresponding to an boxed type.
        Type Parameters:
        T - the type parameter
        Parameters:
        type - the boxed type
        Returns:
        the primitive class
      • wrap

        public static <T> Class<T> wrap​(@NonNull
                                        @NonNull Class<T> type)
        Gets the object type class corresponding to a primitive class.
        Type Parameters:
        T - the type parameter
        Parameters:
        type - the primitive type
        Returns:
        the wrapped type class