Class Assert

java.lang.Object
com.bc.ceres.core.Assert

public final class Assert extends Object
Assert is useful for embedding runtime sanity checks in code. The predicate methods all test a condition and throw some type of unchecked exception if the condition does not hold.

Assertion failure exceptions, like most runtime exceptions, are thrown when something is misbehaving. Assertion failures are invariably unspecified behavior; consequently, clients should never rely on these being thrown (and certainly should not being catching them specifically).

This class is not intended to be instantiated or sub-classed by clients.

  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    argument(boolean expression)
    Asserts that an argument is legal.
    static boolean
    argument(boolean expression, String message)
    Asserts that an argument is legal.
    static void
    notNull(Object object)
    Asserts that the given object is not null.
    static void
    notNull(Object object, String message)
    Asserts that the given object is not null.
    static boolean
    state(boolean expression)
    Asserts that the given boolean is true.
    static boolean
    state(boolean expression, String message)
    Asserts that the given boolean is true.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • argument

      public static boolean argument(boolean expression)
      Asserts that an argument is legal. If the given boolean is not true, an IllegalArgumentException is thrown.
      Parameters:
      expression - the expression of the check
      Returns:
      true if the check passes (does not return if the check fails)
      Throws:
      IllegalArgumentException - if the legality test failed
    • argument

      public static boolean argument(boolean expression, String message)
      Asserts that an argument is legal. If the given boolean is not true, an IllegalArgumentException is thrown. The given message is included in that exception, to aid debugging.
      Parameters:
      expression - the result of the evaluated argument expression
      message - the message to include in the exception
      Returns:
      true if the check passes (does not return if the check fails)
      Throws:
      IllegalArgumentException - if the legality test failed
    • notNull

      public static void notNull(Object object)
      Asserts that the given object is not null. If this is not the case, some kind of unchecked exception is thrown.
      Parameters:
      object - the value to test
      Throws:
      NullPointerException - if the object is null
    • notNull

      public static void notNull(Object object, String message)
      Asserts that the given object is not null. If this is not the case, some kind of unchecked exception is thrown. The given message is included in that exception, to aid debugging.
      Parameters:
      object - the value to test
      message - the message to include in the exception
      Throws:
      NullPointerException - if the object is null
    • state

      public static boolean state(boolean expression)
      Asserts that the given boolean is true. If this is not the case, some kind of unchecked exception is thrown.
      Parameters:
      expression - the result of the evaluated state expression
      Returns:
      true if the check passes (does not return if the check fails)
      Throws:
      IllegalStateException - if the given boolean is false
    • state

      public static boolean state(boolean expression, String message)
      Asserts that the given boolean is true. If this is not the case, some kind of unchecked exception is thrown. The given message is included in that exception, to aid debugging.
      Parameters:
      expression - the result of the evaluated state expression
      message - the message to include in the exception
      Returns:
      true if the check passes (does not return if the check fails)
      Throws:
      IllegalStateException - if the given boolean is false