Package com.gengoai
Class Primitives
- java.lang.Object
-
- com.gengoai.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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
defaultValue(@NonNull Class<T> clazz)
Gets the default value of the given class (primitive and boxed versions all other classes will result in null)static byte[]
toByteArray(@NonNull Iterable<? extends Number> numbers)
Converts and iterable of numbers to an array of bytestatic char[]
toCharArray(@NonNull Iterable<Character> characters)
Converts and iterable of Character to an array of charstatic double[]
toDoubleArray(@NonNull Iterable<? extends Number> numbers)
Converts and iterable of numbers to an array of doublestatic float[]
toFloatArray(@NonNull Iterable<? extends Number> numbers)
Converts and iterable of numbers to an array of floatstatic int[]
toIntArray(@NonNull Iterable<? extends Number> numbers)
Converts and iterable of numbers to an array of intstatic long[]
toLongArray(@NonNull Iterable<? extends Number> numbers)
Converts and iterable of numbers to an array of longstatic short[]
toShortArray(@NonNull Iterable<? extends Number> numbers)
Converts and iterable of numbers to an array of shortstatic <T> Class<T>
unwrap(Class<T> type)
Gets the primitive type class corresponding to an boxed type.static <T> Class<T>
wrap(@NonNull Class<T> type)
Gets the object type class corresponding to a primitive class.
-
-
-
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
-
-