Class Check


  • public class Check
    extends Object
    Collection of static utility methods for checking variable state and arguments.
    Author:
    mtaal
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void fail​(String message)
      Always throws a CheckException.
      static void isFalse​(boolean value, String message)
      Throws a CheckException if the value is true, the message is used for creating the Exception.
      static void isInstanceOf​(Object obj, Class<?> expClass)
      Checks if the passed object is of the class specified, null values are ignored.
      static void isNotNull​(Object value, String message)  
      static void isNotSameObject​(Object obj1, Object obj2)
      Checks memory equality, the two objects should not be the exact same object.
      static void isNull​(Object value, String message)
      Throws a CheckException if the value is not null, the message is used for creating the Exception.
      static void isSameObject​(Object obj1, Object obj2)
      Checks memory equality, the two objects should be the exact same object.
      static void isTrue​(boolean value, String message)
      Throws a CheckException if the value is false, the message is used for creating the Exception.
      static void notEmpty​(Object[] array, String message)
      Throws a CheckException if the value is null or has length 0 (after trimming), the message is used for creating the Exception.
      static void notEmpty​(String value, String message)
      Throws a CheckException if the value is null or has length 0 (after trimming), the message is used for creating the Exception.
    • Method Detail

      • fail

        public static void fail​(String message)
        Always throws a CheckException.
        Parameters:
        message - the message used for the exception
        Throws:
        CheckException
      • isTrue

        public static void isTrue​(boolean value,
                                  String message)
        Throws a CheckException if the value is false, the message is used for creating the Exception.
        Parameters:
        value - should be true otherwise an Exception is thrown
        message - the message used for the Exception
        Throws:
        CheckException
      • isFalse

        public static void isFalse​(boolean value,
                                   String message)
        Throws a CheckException if the value is true, the message is used for creating the Exception.
        Parameters:
        value - should be false otherwise an Exception is thrown
        message - the message used for the Exception
        Throws:
        CheckException
      • isNotNull

        public static void isNotNull​(Object value,
                                     String message)
      • isNull

        public static void isNull​(Object value,
                                  String message)
        Throws a CheckException if the value is not null, the message is used for creating the Exception.
        Parameters:
        value - should be null otherwise an Exception is thrown
        message - the message used for the Exception
        Throws:
        CheckException
      • notEmpty

        public static void notEmpty​(String value,
                                    String message)
        Throws a CheckException if the value is null or has length 0 (after trimming), the message is used for creating the Exception.
        Parameters:
        value - should be unequal to null and have length > zero otherwise an Exception is thrown
        message - the message used for the Exception
        Throws:
        CheckException
      • notEmpty

        public static void notEmpty​(Object[] array,
                                    String message)
        Throws a CheckException if the value is null or has length 0 (after trimming), the message is used for creating the Exception.
        Parameters:
        array - should be unequal to null and have length > zero otherwise an Exception is thrown
        message - the message used for the Exception
        Throws:
        CheckException
      • isInstanceOf

        public static void isInstanceOf​(Object obj,
                                        Class<?> expClass)
        Checks if the passed object is of the class specified, null values are ignored.
        Parameters:
        obj - should be instanceof the expClass
        expClass - the class used for the check
        Throws:
        CheckException
      • isSameObject

        public static void isSameObject​(Object obj1,
                                        Object obj2)
        Checks memory equality, the two objects should be the exact same object.
        Parameters:
        obj1 - first object checked
        obj2 - second object checked
        Throws:
        CheckException
      • isNotSameObject

        public static void isNotSameObject​(Object obj1,
                                           Object obj2)
        Checks memory equality, the two objects should not be the exact same object.
        Parameters:
        obj1 - first object checked
        obj2 - second object checked
        Throws:
        CheckException