@Status(stage=PRODUCTION, unitTests=PARTIAL) @Review(by="Kees Schotanus", at="2009-09-28") public final class CDebug extends Object
public void method(final String value) {
CDebug.checkParameterNotEmpty(value, ParameterName.VALUE);
...
}
The method above checks that the supplied parameter is neither null nor
empty. Many more methods like the one above exist!
if (CDebug.isDebugEnabled()) {
CDebug.checkParameterTrue(expensive_expression(), ParameterName.MESSAGE);
}
This construction prevents the expensive_expression() from being evaluated
when debug mode is disabled.setDebug(boolean)
method with a value of true or use
-Ddebug=true as a VM argument.Modifier and Type | Method and Description |
---|---|
static void |
checkParameterNotEmpty(Collection<?> collectionParameter,
String parameterName)
Checks that the supplied collectionParameter reference is not empty.
|
static void |
checkParameterNotEmpty(double[] arrayParameter,
String parameterName)
Checks that the supplied arrayParameter reference is not empty.
|
static void |
checkParameterNotEmpty(Object[] arrayParameter,
String parameterName)
Checks that the supplied arrayParameter reference is not empty.
|
static void |
checkParameterNotEmpty(String parameter,
String parameterName)
Checks that the supplied String parameter reference is not empty.
|
static void |
checkParameterNotNull(Object parameter,
String parameterName)
Checks that the supplied parameter reference is not null.
|
static void |
checkParameterTrue(boolean expression,
String message)
Checks that the supplied boolean value (expression) is true.
|
static String |
getStackTrace(Throwable throwable)
Gets the stack trace from the supplied throwable.
|
static void |
invariant(boolean expression)
Checks that the supplied boolean invariant is true.
|
static void |
invariant(boolean expression,
String message)
Checks that the supplied boolean invariant is true.
|
static boolean |
isDebugEnabled()
Determines whether debug mode is enabled (true) or disabled (false).
|
static void |
postcondition(boolean expression)
Checks that the supplied boolean postcondition is true.
|
static void |
postcondition(boolean expression,
String message)
Checks that the supplied boolean postcondition is true.
|
static void |
precondition(boolean expression)
Checks that the supplied boolean precondition is true.
|
static void |
precondition(boolean expression,
String message)
Checks that the supplied boolean precondition is true.
|
static void |
setDebug(boolean debug)
Enables or disables the josef debug mode.
|
public static boolean isDebugEnabled()
public static void setDebug(boolean debug)
isDebugEnabled()
method.debug
- Supply true to enable josef debug mode, supply false to
disable the josef debug mode.public static void precondition(boolean expression)
expression
- Boolean expression to check.IllegalStateException
- When the precondition fails.public static void precondition(boolean expression, String message)
expression
- Boolean expression to check.message
- Message to write when the precondition fails.IllegalStateException
- When the precondition fails.public static void invariant(boolean expression)
expression
- Boolean expression to check.IllegalStateException
- When the invariant is broken.public static void invariant(boolean expression, String message)
expression
- Boolean expression to check.message
- Message to write when the invariant is broken.IllegalStateException
- When the invariant is broken.public static void postcondition(boolean expression)
expression
- Boolean expression to check.IllegalStateException
- When the postcondition fails.public static void postcondition(boolean expression, String message)
expression
- Boolean expression to check.message
- Message to write when the postcondition fails.IllegalStateException
- When the postcondition fails.public static void checkParameterTrue(boolean expression, String message)
expression
- Boolean expression to check.message
- Message to write when the check fails.IllegalArgumentException
- When the supplied boolean expression is
false.public static void checkParameterNotNull(Object parameter, String parameterName)
parameter
- Parameter reference to check that it is not null.parameterName
- Name of the parameter.NullPointerException
- When the supplied parameter is null.public static void checkParameterNotEmpty(String parameter, String parameterName)
parameter
- String parameter reference to check that it is not
empty.parameterName
- Name of the String reference.IllegalArgumentException
- When the supplied parameter is empty.NullPointerException
- When the supplied parameter is null.public static void checkParameterNotEmpty(Object[] arrayParameter, String parameterName)
arrayParameter
- Array parameter reference to check that it is not
empty.parameterName
- Name of the array reference.IllegalArgumentException
- When the supplied arrayParameter is
empty.NullPointerException
- When the supplied arrayParameter is null.public static void checkParameterNotEmpty(double[] arrayParameter, String parameterName)
arrayParameter
- Array parameter reference to check that it is not
empty.parameterName
- Name of the array reference.IllegalArgumentException
- When the supplied arrayParameter is
empty.NullPointerException
- When the supplied arrayParameter is null.public static void checkParameterNotEmpty(Collection<?> collectionParameter, String parameterName)
collectionParameter
- Collection parameter reference to check that
it is not empty.parameterName
- Name of the Collection reference.IllegalArgumentException
- When the supplied collectionParameter
is empty.NullPointerException
- When the supplied collectionParameter is
null.public static String getStackTrace(Throwable throwable)
throwable
- The throwable containing the stack trace.NullPointerException
- When the supplied throwable is null.Copyright © 2008–2018. All rights reserved.