Class Arrays


  • public class Arrays
    extends java.lang.Object
    Utility methods related to arrays.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Arrays()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int[] array​(java.util.concurrent.atomic.AtomicIntegerArray atomicIntegerArray)
      Returns an int[] from the AtomicIntegerArray, null if the given atomic array is null.
      static long[] array​(java.util.concurrent.atomic.AtomicLongArray atomicLongArray)
      Returns an long[] from the AtomicLongArray, null if the given atomic array is null.
      static <T> T[] array​(java.util.concurrent.atomic.AtomicReferenceArray<T> atomicReferenceArray)
      Returns an T[] from the AtomicReferenceArray, null if the given atomic array is null.
      static <T> T[] array​(T... values)
      Returns an array containing the given arguments.
      static java.util.List<java.lang.Object> asList​(java.lang.Object array)
      Get the values of any array (primitive or not) into a List<Object>.
      static java.lang.Object[] asObjectArray​(java.lang.Object array)
      Get the values of any array (primitive or not) into a Object[].
      static <T> boolean hasOnlyNullElements​(T[] array)
      Returns true if the given array has only null elements, false otherwise.
      static boolean isArray​(java.lang.Object o)
      Indicates whether the given object is not null and is an array.
      static boolean isArrayEmpty​(java.lang.Object array)  
      static boolean isArrayTypePrimitive​(java.lang.Object o)  
      private static <T> boolean isEmpty​(T[] array)  
      static <T> boolean isNullOrEmpty​(T[] array)
      Indicates whether the given array is null or empty.
      static boolean isObjectArray​(java.lang.Object o)  
      static <T> java.util.List<T> nonNullElementsIn​(T[] array)
      Returns all the non-null elements in the given array.
      static java.lang.IllegalArgumentException notAnArrayOfPrimitives​(java.lang.Object o)  
      static <T> T[] prepend​(T first, T... rest)  
      static int sizeOf​(java.lang.Object array)  
      • Methods inherited from class java.lang.Object

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

      • Arrays

        private Arrays()
    • Method Detail

      • isArray

        public static boolean isArray​(java.lang.Object o)
        Indicates whether the given object is not null and is an array.
        Parameters:
        o - the given object.
        Returns:
        true if the given object is not null and is an array, otherwise false.
      • asObjectArray

        public static java.lang.Object[] asObjectArray​(java.lang.Object array)
        Get the values of any array (primitive or not) into a Object[].
        Parameters:
        array - array passed as an object to support both primitive and Object array
        Returns:
        the values of the given Object as a Object[].
        Throws:
        java.lang.IllegalArgumentException - it the given Object is not an array.
      • asList

        public static java.util.List<java.lang.Object> asList​(java.lang.Object array)
        Get the values of any array (primitive or not) into a List<Object>.
        Parameters:
        array - array passed as an object to support both primitive and Object array
        Returns:
        the values of the given Object as a List<Object>.
        Throws:
        java.lang.IllegalArgumentException - it the given Object is not an array.
      • isNullOrEmpty

        public static <T> boolean isNullOrEmpty​(T[] array)
        Indicates whether the given array is null or empty.
        Type Parameters:
        T - the type of elements of the array.
        Parameters:
        array - the array to check.
        Returns:
        true if the given array is null or empty, otherwise false.
      • array

        @SafeVarargs
        public static <T> T[] array​(T... values)
        Returns an array containing the given arguments.
        Type Parameters:
        T - the type of the array to return.
        Parameters:
        values - the values to store in the array.
        Returns:
        an array containing the given arguments.
      • array

        public static int[] array​(java.util.concurrent.atomic.AtomicIntegerArray atomicIntegerArray)
        Returns an int[] from the AtomicIntegerArray, null if the given atomic array is null.
        Parameters:
        atomicIntegerArray - the AtomicIntegerArray to convert to int[].
        Returns:
        an int[].
      • array

        public static long[] array​(java.util.concurrent.atomic.AtomicLongArray atomicLongArray)
        Returns an long[] from the AtomicLongArray, null if the given atomic array is null.
        Parameters:
        atomicLongArray - the AtomicLongArray to convert to long[].
        Returns:
        an long[].
      • array

        public static <T> T[] array​(java.util.concurrent.atomic.AtomicReferenceArray<T> atomicReferenceArray)
        Returns an T[] from the AtomicReferenceArray, null if the given atomic array is null.
        Type Parameters:
        T - the type of elements of the array.
        Parameters:
        atomicReferenceArray - the AtomicReferenceArray to convert to T[].
        Returns:
        an T[].
      • nonNullElementsIn

        public static <T> java.util.List<T> nonNullElementsIn​(T[] array)
        Returns all the non-null elements in the given array.
        Type Parameters:
        T - the type of elements of the array.
        Parameters:
        array - the given array.
        Returns:
        all the non-null elements in the given array. An empty list is returned if the given array is null.
      • hasOnlyNullElements

        public static <T> boolean hasOnlyNullElements​(T[] array)
        Returns true if the given array has only null elements, false otherwise. If given array is empty, this method returns true.
        Type Parameters:
        T - the type of elements of the array.
        Parameters:
        array - the given array. It must not be null.
        Returns:
        true if the given array has only null elements or is empty, false otherwise.
        Throws:
        java.lang.NullPointerException - if the given array is null.
      • isEmpty

        private static <T> boolean isEmpty​(T[] array)
      • isObjectArray

        public static boolean isObjectArray​(java.lang.Object o)
      • isArrayTypePrimitive

        public static boolean isArrayTypePrimitive​(java.lang.Object o)
      • notAnArrayOfPrimitives

        public static java.lang.IllegalArgumentException notAnArrayOfPrimitives​(java.lang.Object o)
      • prepend

        public static <T> T[] prepend​(T first,
                                      T... rest)
      • sizeOf

        public static int sizeOf​(java.lang.Object array)
      • isArrayEmpty

        public static boolean isArrayEmpty​(java.lang.Object array)