Class ArgCheck


  • public class ArgCheck
    extends Object
    This class contains a set of static utility methods for checking method arguments. It contains many of the common checks that are done, such as checking that an Object is non-null, checking the range of a value, etc. All of these methods throw IllegalArgumentException.
    • Method Detail

      • isTrue

        public static final void isTrue​(boolean condition,
                                        String message)
        Check that the boolean condition is true; throw an IllegalArgumentException if not.
        Parameters:
        condition - The boolean condition to check
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - if condition is false
      • isNonNegative

        public static final void isNonNegative​(int value)
        Check that the value is non-negative (>=0).
        Parameters:
        value - Value
        Throws:
        IllegalArgumentException - If value is negative (<0)
      • isNonNegative

        public static final void isNonNegative​(int value,
                                               String message)
        Check that the value is non-negative (>=0).
        Parameters:
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is negative (<0)
      • isNonPositive

        public static final void isNonPositive​(int value)
        Check that the value is non-positive (<=0).
        Parameters:
        value - Value
        Throws:
        IllegalArgumentException - If value is positive (>0)
      • isNonPositive

        public static final void isNonPositive​(int value,
                                               String message)
        Check that the value is non-positive (<=0).
        Parameters:
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is positive (>0)
      • isNegative

        public static final void isNegative​(int value)
        Check that the value is negative (<0).
        Parameters:
        value - Value
        Throws:
        IllegalArgumentException - If value is non-negative (>=0)
      • isNegative

        public static final void isNegative​(int value,
                                            String message)
        Check that the value is negative (<0).
        Parameters:
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is non-negative (>=0)
      • isPositive

        public static final void isPositive​(int value)
        Check that the value is positive (>0).
        Parameters:
        value - Value
        Throws:
        IllegalArgumentException - If value is non-positive (<=0)
      • isPositive

        public static final void isPositive​(int value,
                                            String message)
        Check that the value is positive (>0).
        Parameters:
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is non-positive (<=0)
      • isNonNegative

        public static final void isNonNegative​(long value)
        Check that the value is non-negative (>=0).
        Parameters:
        value - Value
        Throws:
        IllegalArgumentException - If value is negative (<0)
      • isNonNegative

        public static final void isNonNegative​(long value,
                                               String message)
        Check that the value is non-negative (>=0).
        Parameters:
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is negative (<0)
      • isNonPositive

        public static final void isNonPositive​(long value)
        Check that the value is non-positive (<=0).
        Parameters:
        value - Value
        Throws:
        IllegalArgumentException - If value is positive (>0)
      • isNonPositive

        public static final void isNonPositive​(long value,
                                               String message)
        Check that the value is non-positive (<=0).
        Parameters:
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is positive (>0)
      • isNegative

        public static final void isNegative​(long value)
        Check that the value is negative (<0).
        Parameters:
        value - Value
        Throws:
        IllegalArgumentException - If value is non-negative (>=0)
      • isNegative

        public static final void isNegative​(long value,
                                            String message)
        Check that the value is negative (<0).
        Parameters:
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is non-negative (>=0)
      • isPositive

        public static final void isPositive​(long value)
        Check that the value is positive (>0).
        Parameters:
        value - Value
        Throws:
        IllegalArgumentException - If value is non-positive (<=0)
      • isPositive

        public static final void isPositive​(long value,
                                            String message)
        Check that the value is positive (>0).
        Parameters:
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is non-positive (<=0)
      • isNotZeroLength

        public static final void isNotZeroLength​(String value)
        Check that the string is non-null and has length > 0
        Parameters:
        value - Value
        Throws:
        IllegalArgumentException - If value is null or length == 0
      • isNotZeroLength

        public static final void isNotZeroLength​(String value,
                                                 String message)
        Check that the string is non-null and has length > 0
        Parameters:
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is null or length == 0
      • isNotNull

        public static final void isNotNull​(Object value)
        Check that the object is non-null
        Parameters:
        value - Value
        Throws:
        IllegalArgumentException - If value is null
      • isNotNull

        public static final void isNotNull​(Object value,
                                           String message)
        Check that the object is non-null
        Parameters:
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is null
      • isNull

        public static final void isNull​(Object value)
        Check that the object is null
        Parameters:
        value - Value
        Throws:
        IllegalArgumentException - If value is non-null
      • isNull

        public static final void isNull​(Object value,
                                        String message)
        Check that the object is null
        Parameters:
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is non-null
      • isInstanceOf

        public static final void isInstanceOf​(Class theClass,
                                              Object value)
        Check that the object is an instance of the specified Class
        Parameters:
        theClass - Class
        value - Value
        Throws:
        IllegalArgumentException - If value is null
      • isInstanceOf

        public static final void isInstanceOf​(Class theClass,
                                              Object value,
                                              String message)
        Check that the object is an instance of the specified Class
        Parameters:
        theClass - Class
        value - Value
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If value is null
      • isNotEmpty

        public static final void isNotEmpty​(Collection collection)
        Check that the collection is not empty
        Parameters:
        collection - Collection
        Throws:
        IllegalArgumentException - If collection is null or empty
      • isNotEmpty

        public static final void isNotEmpty​(Collection collection,
                                            String message)
        Check that the collection is not empty
        Parameters:
        collection - Collection
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If collection is null or empty
      • isNotEmpty

        public static final void isNotEmpty​(Map map)
        Check that the map is not empty
        Parameters:
        map - Map
        Throws:
        IllegalArgumentException - If map is null or empty
      • isNotEmpty

        public static final void isNotEmpty​(Map map,
                                            String message)
        Check that the map is not empty
        Parameters:
        map - Map
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If map is null or empty
      • isNotEmpty

        public static final void isNotEmpty​(Object[] array)
        Check that the array is not empty
        Parameters:
        array - Array
        Throws:
        IllegalArgumentException - If array is null or empty
        Since:
        3.1
      • isNotEmpty

        public static final void isNotEmpty​(Object[] array,
                                            String message)
        Check that the array is not empty
        Parameters:
        array - Array
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If array is null or empty
        Since:
        3.1
      • isNotEmpty

        public static final void isNotEmpty​(String string)
        Check that the string is not empty
        Parameters:
        string - String
        Throws:
        IllegalArgumentException - If string is null or empty
        Since:
        3.1
      • isNotEmpty

        public static final void isNotEmpty​(String string,
                                            String message)
        Check that the string is not empty
        Parameters:
        string - String
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If string is null or empty
        Since:
        3.1
      • isNotSame

        public static void isNotSame​(Object firstObject,
                                     String firstName,
                                     Object secondObject,
                                     String secondName)
        Asserts that the specified first object is not the same as (==) the specified second object.
        Parameters:
        firstObject - The first object to assert as not the same as the second object.
        firstName - The name that will be used within the exception message for the first object, should an exception be thrown; if null and firstObject is not null, firstObject.toString() will be used.
        secondObject - The second object to assert as not the same as the first object.
        secondName - The name that will be used within the exception message for the second object, should an exception be thrown; if null and secondObject is not null, secondObject.toString() will be used.
        Throws:
        IllegalArgumentException - If the specified objects are the same.
        Since:
        3.1
      • contains

        public static final void contains​(Collection collection,
                                          Object value)
        Check that the collection contains the value
        Parameters:
        collection - Collection to check
        value - Value to check for, may be null
        Throws:
        IllegalArgumentException - If collection is null or doesn't contain value
      • contains

        public static final void contains​(Collection collection,
                                          Object value,
                                          String message)
        Check that the collection contains the value
        Parameters:
        collection - Collection to check
        value - Value to check for, may be null
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If collection is null or doesn't contain value
      • containsKey

        public static final void containsKey​(Map map,
                                             Object key)
        Check that the map contains the key
        Parameters:
        map - Map to check
        key - Key to check for, may be null
        Throws:
        IllegalArgumentException - If map is null or doesn't contain key
      • containsKey

        public static final void containsKey​(Map map,
                                             Object key,
                                             String message)
        Check that the map contains the key
        Parameters:
        map - Map to check
        key - Key to check for, may be null
        message - Exception message if check fails
        Throws:
        IllegalArgumentException - If map is null or doesn't contain key