Class ObjectUtils


  • public final class ObjectUtils
    extends Object
    • Method Detail

      • asCollection

        public static <T> Collection<T> asCollection​(Iterator<T> iterator)
        Transfers the given iterator to an unmodifiable collection.
        Type Parameters:
        T - The type of the objects contained in the iterator.
        Parameters:
        iterator - The iterator to transfer.
        Returns:
        Contents of the iterator as an unmodifiable Collection.
      • asList

        public static <T> List<T> asList​(Collection<T> collection)
      • asOrderedCollection

        public static <T> Collection<T> asOrderedCollection​(Iterator<T> iterator,
                                                            Comparator<T> comparator)
        Transfers the given iterator into an unmodifiable ordered collection based on the given comparator.
        Type Parameters:
        T - The type of the objects contained in the iterator.
        Parameters:
        iterator - The iterator to transfer.
        comparator - The comparator to order the collection.
        Returns:
        Contents of the iterator as an unmodifiable ordered Collection.
      • toString

        public static <T> String toString​(T[] array)
      • isEmpty

        public static <T> boolean isEmpty​(Collection<T> collection)
        Type Parameters:
        T - The type of objects in the collection.
        Parameters:
        collection - The collection to check.
        Returns:
        true if the given collection is null or empty.
      • isEmpty

        public static boolean isEmpty​(String string)
        Parameters:
        string - The string to check.
        Returns:
        true if the given string is null or empty.
      • isNotEmpty

        public static boolean isNotEmpty​(String string)
        Parameters:
        string - The string to check.
        Returns:
        true if the given string is not null and not empty.
      • isNotEmpty

        public static <T> boolean isNotEmpty​(Collection<T> collection)
        Type Parameters:
        T - The type of objects in the collection.
        Parameters:
        collection - The collection to check.
        Returns:
        true if the given collection is not null and not empty.
      • isNull

        public static boolean isNull​(Object object)
        Parameters:
        object - The object to check.
        Returns:
        true if the given object reference is null.
      • isNotNull

        public static boolean isNotNull​(Object object)
        Parameters:
        object - The object to check.
        Returns:
        true if the given object reference is not null.
      • getRandomDate

        public static Date getRandomDate()
        Returns:
        a random Date
      • getRandomNumber

        public static int getRandomNumber()
        Returns:
        4 digit random Integer number
      • getRandomNumber

        public static int getRandomNumber​(int max)
        Parameters:
        max - the upper bound (exclusive)
        Returns:
        random Integer number between 0 and parameter max
      • getLastElement

        public static <T> T getLastElement​(List<T> list)
      • getFirstElement

        public static <T> T getFirstElement​(List<T> list)