Class Args


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

      Constructors 
      Constructor Description
      Args()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isFalse​(boolean argument, java.lang.String msg, java.lang.Object... params)
      Check if argument is false
      static boolean isTrue​(boolean argument, java.lang.String msg, java.lang.Object... params)
      Check if argument is true
      static <T extends java.lang.CharSequence>
      T
      notEmpty​(T argument, java.lang.String name)
      Checks argument is not empty (not null and has a non-whitespace character)
      static <T extends java.util.Collection<?>>
      T
      notEmpty​(T collection, java.lang.String message, java.lang.Object... params)
      Checks argument is not null or empty
      static <T> T notNull​(T argument, java.lang.String name)
      Checks argument is not null
      static <T extends java.lang.Comparable<? super T>>
      T
      withinRange​(T min, T max, T value, java.lang.String name)
      Checks if argument is within a range
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Args

        public Args()
    • Method Detail

      • notNull

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

        public static <T extends java.lang.CharSequence> T notEmpty​(T argument,
                                                                    java.lang.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:
        java.lang.IllegalArgumentException - when the passed argument is empty
      • notEmpty

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

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

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

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

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