org.metasyntactic.debug
Class Assert

java.lang.Object
  |
  +--org.metasyntactic.debug.Assert

public class Assert
extends java.lang.Object

Assertions are boolean expressions that the programmer believes to be true concerning the state of a computer program. For example, after sorting a list, the programmer might assert that the list is in ascending order. Evaluating assertions at runtime to confirm their validity is one of the most powerful tools for improving code quality, as it quickly uncovers the programmer's misconceptions concerning a program's behavior.


Field Summary
static boolean OFF
          Value to pass to setState to turn sssertions off
static boolean ON
          Value to pass to setState to turn sssertions on
 
Method Summary
static void assert(boolean expression)
          Asserts that the value of expression in true.
static void assert(boolean expression, java.lang.String message)
          Asserts that the value of expression in true.
static boolean getState()
          Returns whether or not assertions are on or off
static void reverseState()
          Turns assertions off if they are on, or on if they are off
static void setState(boolean state)
          Sets the state of the assertions cased on value passed in
static void turnOff()
          Turns assertions off
static void turnOn()
          Turns assertions on
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ON

public static boolean ON
Value to pass to setState to turn sssertions on


OFF

public static boolean OFF
Value to pass to setState to turn sssertions off

Method Detail

reverseState

public static void reverseState()
Turns assertions off if they are on, or on if they are off


turnOn

public static void turnOn()
Turns assertions on


turnOff

public static void turnOff()
Turns assertions off


getState

public static boolean getState()
Returns whether or not assertions are on or off

Returns:
ON or OFF

setState

public static void setState(boolean state)
Sets the state of the assertions cased on value passed in

Parameters:
state - ON or OFF

assert

public static void assert(boolean expression)
                   throws AssertionException
Asserts that the value of expression in true. If it is false and asserts are turned on, then an assertion exception will be thrown.

Parameters:
expression - The expression that you are asserting is true
Throws:
AssertionException - if expression is false

assert

public static void assert(boolean expression,
                          java.lang.String message)
                   throws AssertionException
Asserts that the value of expression in true. If it is false and asserts are turned on, then an assertation exception with the given message will be thrown.

Parameters:
expression - The expression you are asserting is true
message - The message you want the assertion exception to contain if it is thrown
Throws:
AssertionException - if expression is false