Class Debug
- Direct Known Subclasses:
JAIDebug
Debug
as it name says is a utility class for debugging. It contains exculisvely static methods and
cannot be instantiated.
This class provides methods for program assertions as well as tracing capabilities. The tracing output can be
redirected to any java.io.XMLCoder
. The debbuging capabilities of this class can be disabled at runtime
by calling Debug.setEnabled(false)
.
The methods defined in this class are guaranteed not to throw any exceptions caused by illegal argument passed to them.
- Version:
- $Revision$ $Date$
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertNotNull
(Object object) If the given object is null, and the debugging functionality is enabled, this method throws anAssertionFailure
in order to signal that an internal program post- or pre-condition failed.static void
assertNotNullOrEmpty
(String string) If the given String is null or empty, and the debugging functionality is enabled, this method throws anAssertionFailure
in order to signal that an internal program post- or pre-condition failed.static void
assertTrue
(boolean condition) If thecondition
is NOT true, and the debugging functionality is enabled, this method throws anAssertionFailure
in order to signal that an internal program post- or pre-condition failed.static void
assertTrue
(boolean condition, String message) If thecondition
is NOT true, and the debugging functionality is enabled, this method throws anAssertionFailure
in order to signal that an internal program post- or pre-condition failed.static PrintWriter
Gets the default writer used for debugging output.static PrintWriter
Gets the current writer that will used for debugging output.static boolean
Checks whether the debugging functionality is enabled or not.static boolean
protected static void
DelegatesDebug.trace()
calls to the system logger.protected static void
DelegatesDebug.trace()
calls to the system logger.static boolean
setEnabled
(boolean enabled) Enables the debugging functionality or disables it.static void
setLogging
(boolean logging) static void
setWriter
(OutputStream stream) Sets the current writer for the given stream that will be used for debugging output.static void
Sets the current writer that will be used for debugging output.static void
trace
(PropertyChangeEvent event) Prints the given property change event to the current writer if and only if the debugging class functionality is enabled.static void
Prints the given message string to the current writer if and only if the debugging class functionality is enabled.static void
static void
static void
Prints the stack trace for the given exeption to the current writer if and only if the debugging class functionality is enabled.static void
CallstraceMemoryUsage(null)
.static void
traceMemoryUsage
(String label) Prints the ammount of free memory using the given label string to the current writer if and only if the debugging class functionality is enabled.static void
traceMethodNotImplemented
(Class clazz, String methodName) Prints a 'method not implemented' message using the given class and method name string to the current writer if and only if the debugging class functionality is enabled.
-
Constructor Details
-
Debug
protected Debug()Protected constructor. Used to prevent object instatiation from this class.
-
-
Method Details
-
isLogging
public static boolean isLogging() -
setLogging
public static void setLogging(boolean logging) -
setEnabled
public static boolean setEnabled(boolean enabled) Enables the debugging functionality or disables it.- Parameters:
enabled
- if true, debugging functionality will be enabled
-
isEnabled
public static boolean isEnabled()Checks whether the debugging functionality is enabled or not.- Returns:
- true, if so
-
getDefaultWriter
Gets the default writer used for debugging output.- Returns:
- the default writer, or
null
if debugging is disabled
-
getWriter
Gets the current writer that will used for debugging output. If no writer was explicitely set by the user, the default writer is returned.- Returns:
- the current writer, or
null
if debugging is disabled
-
setWriter
Sets the current writer that will be used for debugging output.- Parameters:
writer
- the new writer
-
setWriter
Sets the current writer for the given stream that will be used for debugging output.- Parameters:
stream
- the stream that will be used for debugging output
-
trace
Prints the given message string to the current writer if and only if the debugging class functionality is enabled. -
trace
Prints the stack trace for the given exeption to the current writer if and only if the debugging class functionality is enabled. -
trace
Prints the given property change event to the current writer if and only if the debugging class functionality is enabled. -
traceMemoryUsage
public static void traceMemoryUsage()CallstraceMemoryUsage(null)
.- See Also:
-
traceMemoryUsage
Prints the ammount of free memory using the given label string to the current writer if and only if the debugging class functionality is enabled.- Parameters:
label
- an optional label, can be null
-
traceMethodNotImplemented
Prints a 'method not implemented' message using the given class and method name string to the current writer if and only if the debugging class functionality is enabled.- Parameters:
clazz
- the method's classmethodName
- the method's name
-
assertTrue
If thecondition
is NOT true, and the debugging functionality is enabled, this method throws anAssertionFailure
in order to signal that an internal program post- or pre-condition failed.Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the program.
For example, the method can be used to ensure valid arguments passed to private and protected methods.
- Parameters:
condition
- the assert condition- Throws:
AssertionFailure
- ifcondition
evaluates to false and the debugging functionality is enabled
-
assertTrue
If thecondition
is NOT true, and the debugging functionality is enabled, this method throws anAssertionFailure
in order to signal that an internal program post- or pre-condition failed. TheAssertionFailure
will be created with the given error message string.Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the program.
For example, the method can be used to ensure valid arguments passed to private and protected methods.
- Parameters:
condition
- the assert conditionmessage
- an error message- Throws:
AssertionFailure
- ifcondition
evaluates to false and the debugging functionality is enabled
-
assertNotNull
If the given object is null, and the debugging functionality is enabled, this method throws anAssertionFailure
in order to signal that an internal program post- or pre-condition failed.Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the program.
For example, the method can be used to ensure valid arguments passed to private and protected methods.
- Parameters:
object
- the object to test for non-null condition- Throws:
AssertionFailure
- ifobject
is null and the debugging functionality is enabled
-
assertNotNullOrEmpty
If the given String is null or empty, and the debugging functionality is enabled, this method throws anAssertionFailure
in order to signal that an internal program post- or pre-condition failed.Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the program.
For example, the method can be used to ensure valid arguments passed to private and protected methods.
- Parameters:
string
- the String to test for non-null and not empty condition- Throws:
AssertionFailure
- ifString
is null or empty and the debugging functionality is enabled
-
log
DelegatesDebug.trace()
calls to the system logger.- Parameters:
message
- the message to be logged.
-
log
DelegatesDebug.trace()
calls to the system logger.- Parameters:
exception
- the exception to be logged.
-
trace
-
trace
-