cern::gp::util::Assertion Class Reference

Collaboration diagram for cern::gp::util::Assertion:
Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static boolean assertTrue (boolean booleanCond, String stringCond)
static void main (String[] args)

Static Private Member Functions

static final void init ()

Static Private Attributes

static final String NB_ERRORMANAGER_CLASSNAME = "org.openide.ErrorManager"
static boolean IN_NETBEANS
static final String NB_ASSERT_CLASSNAME = "cern.gp.util.NbAssert"
static IAssert NB_ASSERT
static boolean initialized = false

Detailed Description

An assertion class, that enables programmers to make certain affirmations about things that have to be true in the code. If an assertion is broken, this means that there is a bad error in the code. Often, assertions are used in to assure that the parameters of a function call are correct, e.g. if a non-null parameter has been passed.

Author:
Vito Baggiolini
Version:
Revision
1.2

,

Date
2006/09/25 08:52:36

,

Author
acaproni

Member Function Documentation

static boolean cern::gp::util::Assertion::assertTrue ( boolean  booleanCond,
String  stringCond 
) [inline, static]

Assert a function to assert a certain property of the code. If the asserted property is false, the Assertion is violated and an RuntimeException is thrown.

For example, assert that str is non-null:

<blockquote>

  void myFunction(String str) { Assert.assertTrue(str != null, "str != null"); }
  </pre</blockquote> 
  Example: make sure min <= max: <blockquote>

  boolean compare(int min, int max) { Assert.assertTrue(min <= max, "min <=
  max"); }

</blockquote>

  Example: make sure that num is greater or equal 0: 
  <blockquote>

  double squareRoot(double num) { Assert.assertTrue(num >= 0, "num >= 0"); }
  </pre</blockquote> 
 
Parameters:
booleanCond the condition expressed as a boolean
stringCond the same condition, given as a String. This is used to fill in the error message in the Exception that is launched if the Assertion is violated.
Exceptions:
RuntimeException if the Assertion is violated. The message in the exception is the string in the stringCond parameter.
Returns:
the condition, which in this implementation is always true (a RuntimeException is thrown on false condition)

References cern::gp::util::IAssert::doAssert(), IN_NETBEANS, init(), and NB_ASSERT.

Referenced by main().

static final void cern::gp::util::Assertion::init (  )  [inline, static, private]

Lazy initialization method. Checks whether we are in a Netbeans Environment or in a normal environment

References IN_NETBEANS, initialized, NB_ASSERT, NB_ASSERT_CLASSNAME, and NB_ERRORMANAGER_CLASSNAME.

Referenced by assertTrue().

static void cern::gp::util::Assertion::main ( String[]  args  )  [inline, static]

The main program for the Assert class

Parameters:
args The command line arguments

References assertTrue().


Member Data Documentation

boolean cern::gp::util::Assertion::IN_NETBEANS [static, private]

Referenced by assertTrue(), and init().

boolean cern::gp::util::Assertion::initialized = false [static, private]

Referenced by init().

Referenced by assertTrue(), and init().

final String cern::gp::util::Assertion::NB_ASSERT_CLASSNAME = "cern.gp.util.NbAssert" [static, private]

Referenced by init().

final String cern::gp::util::Assertion::NB_ERRORMANAGER_CLASSNAME = "org.openide.ErrorManager" [static, private]

Referenced by init().


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2