Class ObjectUtil


  • public class ObjectUtil
    extends Object
    • Method Detail

      • requireNonEmpty

        public static String requireNonEmpty​(String str)
        Checks that the provided string is not empty.
        Parameters:
        str - the string to check
        Returns:
        the same string
        Throws:
        NullPointerException - if the provided string is null
        IllegalArgumentException - if the provided string is empty
      • requireNonEmpty

        public static String requireNonEmpty​(String str,
                                             String message)
        Checks that the provided string is not empty.
        Parameters:
        str - the string to check
        message - the exception message to use
        Returns:
        the same string
        Throws:
        NullPointerException - if the provided string is null
        IllegalArgumentException - if the provided string is empty
      • requireNonEmpty

        public static <T> Collection<T> requireNonEmpty​(Collection<T> col)
        Checks that the provided collection is not empty.
        Type Parameters:
        T - the contained type of the collection
        Parameters:
        col - the collection to check
        Returns:
        the same collection
        Throws:
        NullPointerException - if the provided collection is null
        IllegalArgumentException - if the provided collection is empty
      • requireNonEmpty

        public static <T> Collection<T> requireNonEmpty​(Collection<T> col,
                                                        String message)
        Checks that the provided collection is not empty.
        Type Parameters:
        T - the contained type of the collection
        Parameters:
        col - the collection to check
        message - the exception message to use
        Returns:
        the same collection
        Throws:
        NullPointerException - if the provided collection is null
        IllegalArgumentException - if the provided collection is empty
      • requireNullOrNonEmpty

        public static String requireNullOrNonEmpty​(String str)
        Checks that the provided string is either null or not empty.
        Parameters:
        str - the string to check
        Returns:
        the same string
        Throws:
        IllegalArgumentException - if the provided string is not null and is empty
      • requireNullOrNonEmpty

        public static String requireNullOrNonEmpty​(String str,
                                                   String message)
        Checks that the provided string is either null or not empty.
        Parameters:
        str - the string to check
        message - the exception message to use
        Returns:
        the same string
        Throws:
        IllegalArgumentException - if the provided string is not null and is empty
      • requireNullOrNonEmpty

        public static <T> Collection<T> requireNullOrNonEmpty​(Collection<T> col)
        Checks that the provided collection is either null or not empty.
        Type Parameters:
        T - the contained type of the collection
        Parameters:
        col - the collection to check
        Returns:
        the same collection
        Throws:
        IllegalArgumentException - if the provided string is not null and is empty
      • requireNullOrNonEmpty

        public static <T> Collection<T> requireNullOrNonEmpty​(Collection<T> col,
                                                              String message)
        Checks that the provided collection is either null or not empty.
        Type Parameters:
        T - the contained type of the collection
        Parameters:
        col - the collection to check
        message - the exception message to use
        Returns:
        the same collection
        Throws:
        IllegalArgumentException - if the provided string is not null and is empty