|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Throwable | +--java.lang.Exception | +--java.lang.RuntimeException | +--oracle.bali.share.Assert
Bali utility class used for adding assertions to Java code.
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 |
public static final boolean DEBUG
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.
assertion(boolean)
Constructor Detail |
public Assert()
Clients never need to call the Assert constructor directly. It is called on behalf of the client from the assertion() method.
assertion(boolean)
public Assert(java.lang.String message)
Clients never need to call the Assert constructor directly. It is called on behalf of the client from the assertion() method.
message
- The message to display when this Assert is thrownMethod Detail |
public static void assert(boolean cond) throws Assert
public static void assert(boolean cond, java.lang.String message) throws Assert
public static void assertion(boolean cond) throws Assert
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.
cond
- The condition to test
Assert
- The Assert exception is thrown if cond is false
DEBUG
public static void assertion(boolean cond, java.lang.String message) throws Assert
cond
- The condition to validate.message
- A message to display if the condition is not valid.
|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |