Class Assertion


  • public final class Assertion
    extends Object

    This class contains a set of static utility methods for assertion checking. Assertions are used to document the assumptions a programmer is making about the code they are writing. Assertions should not be used in cases where the user of a class can affect whether the assertion is true or false, such as argument checking. Rather, assertions should be considered a much stronger statement by the programmer that such a condition is NEVER true. In fact, this statement is so strong that assertions should be considered optional as they should never occur. However, these assertions may be violated during development and that is primarily where these assertions are useful.

    In JDK 1.4, Sun introduces the "assert" keyword and builds assertion support directly into the language. When MetaMatrix begins using JDK 1.4 across the board, this class should no longer be needed and all usage of assertions should be replaced with use of the built-in JDK assertion facility.

    • Method Detail

      • assertTrue

        public static final void assertTrue​(boolean condition)
      • assertTrue

        public static final void assertTrue​(boolean condition,
                                            String msgKey)
      • failed

        public static final void failed​(String msg)
      • isNull

        public static final void isNull​(Object value)
      • isNull

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

        public static final void isNotNull​(Object value)
      • isNotNull

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

        public static final <T> T isInstanceOf​(Object object,
                                               Class<T> expectedClass,
                                               String name)
        Verifies that the specified value is an instance of the specified class.
        Parameters:
        object - The value to verify
        expectedClass - The class of which the value must be an instance
        name - The text identifying the name or type of value
        Throws:
        ClassCastException - If the value is not an instance of the specified class.
        Since:
        2.1