Bali Share 1.1.18

oracle.bali.share
Class Assert

java.lang.Object
  |
  +--java.lang.Throwable
        |
        +--java.lang.Exception
              |
              +--java.lang.RuntimeException
                    |
                    +--oracle.bali.share.Assert
All Implemented Interfaces:
java.io.Serializable

public class Assert
extends java.lang.RuntimeException

Bali utility class used for adding assertions to Java code.

See Also:
Serialized Form

Field Summary
static boolean DEBUG
          Debug constant.
 
Constructor Summary
Assert()
          Constructs a new assertion exception.
Assert(java.lang.String message)
          Constructs a new assertion exception with the specified message.
 
Method Summary
static void assert(boolean cond)
          Deprecated. Please use assertion() instead
static void assert(boolean cond, java.lang.String message)
          Deprecated. Please use assertion instead
static void assertion(boolean cond)
          Asserts that the specified condition is true.
static void assertion(boolean cond, java.lang.String message)
          Asserts with message.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getLocalizedMessage, getMessage, printStackTrace, printStackTrace, printStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
Debug constant. This constant is used in conjunction with the assertion() method to allow clients to write debugging code which can be conditionally compiled in/ out for debugged/optmized code.

Clients are responsible for placing all debugging code/assertions within "if (Assert.DEBUG)" blocks. By setting this constant to false, any such code should be optimized out by the compiler. If set to true, the debugging code will be evaluated at runtime.

See Also:
assertion(boolean)
Constructor Detail

Assert

public Assert()
Constructs a new assertion exception.

Clients never need to call the Assert constructor directly. It is called on behalf of the client from the assertion() method.

See Also:
assertion(boolean)

Assert

public Assert(java.lang.String message)
Constructs a new assertion exception with the specified message.

Clients never need to call the Assert constructor directly. It is called on behalf of the client from the assertion() method.

Parameters:
message - The message to display when this Assert is thrown
Method Detail

assert

public static void assert(boolean cond)
                   throws Assert
Deprecated. Please use assertion() instead


assert

public static void assert(boolean cond,
                          java.lang.String message)
                   throws Assert
Deprecated. Please use assertion instead


assertion

public static void assertion(boolean cond)
                      throws Assert
Asserts that the specified condition is true.

Calls to assertion() must always be placed within an "if (Assert.DEBUG)" expression in order to guarantee that the assertion code is not evaluated in optimized code. The following code demonstrates how to correctly use assertion():

   if (Assert.DEBUG)
   {
     Assert.assertion((lineStyle & ~(SHOW_ROOTLINES | SHOW_LINES)) == 0)
   }
 
Note that this assertion() method is different from the usual C assert funtion in that it requires the client be responsible for ensuring that the assertion code does not get compiled in to optimized code. Also note that the conditional test for debugging must be coded exactly as demonstrated above, which relies on the fact that most Java compilers will be able to optimize out code of the form -
   if (false) { ... }
 
If the conditional test includes any operation other than the evaluation of a boolean constant, the conditional test will most likely not be compiled out and instead will be evaluated at runtime.

Parameters:
cond - The condition to test

Throws:
Assert - The Assert exception is thrown if cond is false

See Also:
DEBUG

assertion

public static void assertion(boolean cond,
                             java.lang.String message)
                      throws Assert
Asserts with message.

Parameters:
cond - The condition to validate.
message - A message to display if the condition is not valid.

Bali Share 1.1.18