Package org.fest.util

Class Arrays


  • public class Arrays
    extends java.lang.Object
    Utility methods related to arrays.
    Author:
    Alex Ruiz, Joel Costigliola
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T[] array​(T... values)
      Returns an array containing the given arguments.
      static java.lang.String format​(java.lang.Object array)
      Returns the String representation of the given array, or null if the given object is either null or not an array.
      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 <T> boolean isNullOrEmpty​(T[] array)
      Indicates whether the given array is null or empty.
      static <T> java.util.List<T> nonNullElementsIn​(T[] array)
      Returns all the non-null elements in the given array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
      • 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

        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.
      • format

        public static java.lang.String format​(java.lang.Object array)
        Returns the String representation of the given array, or null if the given object is either null or not an array. This method supports arrays having other arrays as elements.
        Parameters:
        array - the object that is expected to be an array.
        Returns:
        the String representation of the given array.
      • 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.
        Since:
        1.1.3
      • 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.
        Since:
        1.1.3