Class Args


  • public class Args
    extends Object
    Class with methods for asserting conditions on arguments.
    • Constructor Detail

      • Args

        public Args()
    • Method Detail

      • notNull

        public static <T> T notNull​(T argument,
                                    String name)
        Checks argument is not null
        Type Parameters:
        T -
        Parameters:
        argument -
        name -
        Returns:
        The 'argument' parameter
        Throws:
        IllegalArgumentException
      • notEmpty

        public static <T extends CharSequence> T notEmpty​(T argument,
                                                          String name)
        Checks argument is not empty (not null and has a non-whitespace character)
        Type Parameters:
        T - the type of the argument to check for emptiness
        Parameters:
        argument - the argument to check for emptiness
        name - the name to use in the error message
        Returns:
        The argument parameter if not empty
        Throws:
        IllegalArgumentException - when the passed argument is empty
      • notEmpty

        public static String notEmpty​(String argument,
                                      String name)
        Checks argument is not empty (not null and has a non-whitespace character) Note: This method overloads notEmpty(CharSequence, String) for performance reasons.
        Parameters:
        argument - the argument to check for emptiness
        name - the name to use in the error message
        Returns:
        The argument parameter if not empty
        Throws:
        IllegalArgumentException - when the passed argument is empty
      • notEmpty

        public static <T extends Collection<?>> T notEmpty​(T collection,
                                                           String message,
                                                           Object... params)
        Checks argument is not null or empty
        Parameters:
        collection -
        message -
        params -
        Returns:
        the {code collection}
        Throws:
        IllegalArgumentException - if the passed collection is either null or empty
      • notEmpty

        public static <T extends Collection<?>> T notEmpty​(T collection,
                                                           String name)
        Checks argument is not null or empty
        Parameters:
        collection -
        name -
        Returns:
        the {code collection}
        Throws:
        IllegalArgumentException - if the passed collection is either null or empty
      • withinRange

        public static <T extends Comparable<? super T>> T withinRange​(T min,
                                                                      T max,
                                                                      T value,
                                                                      String name)
        Checks if argument is within a range
        Type Parameters:
        T -
        Parameters:
        min -
        max -
        value -
        name -
        Returns:
        the {code value}
        Throws:
        IllegalArgumentException
      • isTrue

        public static boolean isTrue​(boolean argument,
                                     String msg,
                                     Object... params)
        Check if argument is true
        Parameters:
        argument -
        msg -
        params -
        Returns:
        argument
      • isFalse

        public static boolean isFalse​(boolean argument,
                                      String msg,
                                      Object... params)
        Check if argument is false
        Parameters:
        argument -
        msg -
        params -
        Returns:
        argument