Class ObjectUtils


  • public final class ObjectUtils
    extends Object
    • Field Detail

      • EMPTY_CLASS_ARRAY

        public static final Class<?>[] EMPTY_CLASS_ARRAY
      • EMPTY_STRING_ARRAY

        public static final String[] EMPTY_STRING_ARRAY
      • EMPTY_ANNOTATION_ARRAY

        public static final Annotation[] EMPTY_ANNOTATION_ARRAY
    • Method Detail

      • defaultIfNull

        public static <T> T defaultIfNull​(T object,
                                          T defaultValue)

        Returns a default value if the object passed is null.

         ObjectUtils.defaultIfNull(null, null)      = null
         ObjectUtils.defaultIfNull(null, "")        = ""
         ObjectUtils.defaultIfNull(null, "zz")      = "zz"
         ObjectUtils.defaultIfNull("abc", *)        = "abc"
         ObjectUtils.defaultIfNull(Boolean.TRUE, *) = Boolean.TRUE
         
        Type Parameters:
        T - the type of the object
        Parameters:
        object - the Object to test, may be null
        defaultValue - the default value to return, may be null
        Returns:
        object if it is not null, defaultValue otherwise
      • isEmptyArray

        public static boolean isEmptyArray​(Object array)
      • arrayContains

        public static boolean arrayContains​(Object[] array,
                                            Object objectToFind)

        Checks if the object is in the given array.

        The method returns false if a null array is passed in.

        Parameters:
        array - the array to search through
        objectToFind - the object to find
        Returns:
        true if the array contains the object
      • indexOf

        public static int indexOf​(Object[] array,
                                  Object objectToFind)
      • arrayAdd

        public static <T> T[] arrayAdd​(T[] array,
                                       T objectToAdd)