org.jsesoft.jse
Class Assert

java.lang.Object
  |
  +--org.jsesoft.jse.Root
        |
        +--org.jsesoft.jse.Assert

public final class Assert
extends Root

A work-around for assertions lacking in Java.


Summary:
The Assert class provides a rudimentary assertion mechanism. This mechanism serves for checking runtime conditions throwing an error if the check fails.

Description:
The Assert class provides two overloads of the assert function. Both check the specified runtime condition and throw an assertion error in case the condition does not hold. Whether or not this assertion is in effect is controlled by the system property ASSERT and the class variable inEffect, resp. If it is defined, the error might be thrown. If it is not defined, the error will not be thrown noway.

By convention, the (optional) message argument contains the checked condition as a String.

Usage:
Assert.assert( ref != null, "ref != null" );

Version:
$Revision: 1.1.1.1 $ $Modtime: 18.11.02 12:33 $

Field Summary
 
Fields inherited from class org.jsesoft.jse.Root
logger, messages, resources
 
Method Summary
static void ASSERT(boolean assertion)
          Checks the runtime-condition and throws an error if check failed.
static void ASSERT(boolean assertion, java.lang.String message)
          Checks the runtime-condition and throws an error with a custom message if check failed.
static boolean isInEffect()
          Checks whether or not the assertion mechanism is in effect.
static void setInEffect(boolean value)
          Sets the inEffect property to a new value.
 
Methods inherited from class org.jsesoft.jse.Root
decrementNumber, getResourceMessage, getResourceMessage, getResourceObject, getResourceString, incrementNumber, intFromByteArray, intToByteArray, longFromByteArray, longToByteArray, setMessageResourceBundle, setPackageResourceBundle, shortFromByteArray, shortToByteArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isInEffect

public static boolean isInEffect()
Checks whether or not the assertion mechanism is in effect.

If this function returns true, the assertion mechanism is in effect, that is, errors are thrown if the assertion is false.

Returns:
the value of the inEffect property

setInEffect

public static void setInEffect(boolean value)
Sets the inEffect property to a new value.

Parameters:
value - the new value of the inEffect property

ASSERT

public static void ASSERT(boolean assertion,
                          java.lang.String message)
Checks the runtime-condition and throws an error with a custom message if check failed.

This method checks the boolean assertion. If the assertion mechanism is in effect and the assertion is false, it throws an error with the specified message.

Parameters:
assertion - the runtime-condition to check
message - the message to print
Throws:
AssertionError - if the assertion is false

ASSERT

public static void ASSERT(boolean assertion)
Checks the runtime-condition and throws an error if check failed.

This method checks the boolean assertion. If the assertion mechanism is in effect and the assertion is false, it throws an error with a null message.

Parameters:
assertion - the runtime-condition to check
Throws:
AssertionError - if the assertion is false