org.oreodata.util
Class Assert

java.lang.Object
  |
  +--org.oreodata.util.Assert

public class Assert
extends java.lang.Object

A helper class that gives us functionality equivalent to C's stdlib assert() macro. Note that assertions should be guarded within code that is conditionally compiled. Try to keep to Eiffel's assertion system. Use static variables defined in a globally used interface class to control the inclusion/exclusion of the blocks of code that contain our assertions. Fie on Joy & Gosling for not having built this into the language.

Author:
Paul Murphy murphy@niggle.com

Constructor Summary
Assert()
           
 
Method Summary
static void asert(boolean b)
           
static void asert(boolean b, java.lang.String msg)
          The most basic assertion test - a boolean test with a message explaining it.
static void canWriteToFile(java.lang.String filename)
          convenient method that throws an IOException if the file cannot be written to.
static void hasContent(java.lang.String s)
          Special assertion for Strings.
static void rethrow(java.lang.Throwable t)
          convenience method to rethrow an exception as a RuntimeException.
static void setFatal(boolean b)
          Set fatal to true to cause system exit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Assert

public Assert()
Method Detail

setFatal

public static void setFatal(boolean b)
Set fatal to true to cause system exit


asert

public static void asert(boolean b,
                         java.lang.String msg)
The most basic assertion test - a boolean test with a message explaining it.


asert

public static void asert(boolean b)

hasContent

public static void hasContent(java.lang.String s)
Special assertion for Strings. Checks for a string being non-null AND non-zero length.


rethrow

public static void rethrow(java.lang.Throwable t)
convenience method to rethrow an exception as a RuntimeException. t is an instanceof RuntimeException, it just rethrows, otherwise, it throws a wrapped AssertionFailedException


canWriteToFile

public static void canWriteToFile(java.lang.String filename)
                           throws java.io.IOException
convenient method that throws an IOException if the file cannot be written to. To get through this method, either (a) the file exists and we can write to it or (b) the file does not exist, but the directory exists and can be written to, i.e. we can create the file there. And otherwise, we get an exception.

java.io.IOException