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 voidassertNotNull(Object object) If the given object is null, and the debugging functionality is enabled, this method throws anAssertionFailurein order to signal that an internal program post- or pre-condition failed.static voidassertNotNullOrEmpty(String string) If the given String is null or empty, and the debugging functionality is enabled, this method throws anAssertionFailurein order to signal that an internal program post- or pre-condition failed.static voidassertTrue(boolean condition) If theconditionis NOT true, and the debugging functionality is enabled, this method throws anAssertionFailurein order to signal that an internal program post- or pre-condition failed.static voidassertTrue(boolean condition, String message) If theconditionis NOT true, and the debugging functionality is enabled, this method throws anAssertionFailurein order to signal that an internal program post- or pre-condition failed.static PrintWriterGets the default writer used for debugging output.static PrintWriterGets the current writer that will used for debugging output.static booleanChecks whether the debugging functionality is enabled or not.static booleanprotected static voidDelegatesDebug.trace()calls to the system logger.protected static voidDelegatesDebug.trace()calls to the system logger.static booleansetEnabled(boolean enabled) Enables the debugging functionality or disables it.static voidsetLogging(boolean logging) static voidsetWriter(OutputStream stream) Sets the current writer for the given stream that will be used for debugging output.static voidSets the current writer that will be used for debugging output.static voidtrace(PropertyChangeEvent event) Prints the given property change event to the current writer if and only if the debugging class functionality is enabled.static voidPrints the given message string to the current writer if and only if the debugging class functionality is enabled.static voidstatic voidstatic voidPrints the stack trace for the given exeption to the current writer if and only if the debugging class functionality is enabled.static voidCallstraceMemoryUsage(null).static voidtraceMemoryUsage(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 voidtraceMethodNotImplemented(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
nullif 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
nullif 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 theconditionis NOT true, and the debugging functionality is enabled, this method throws anAssertionFailurein 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- ifconditionevaluates to false and the debugging functionality is enabled
-
assertTrue
If theconditionis NOT true, and the debugging functionality is enabled, this method throws anAssertionFailurein order to signal that an internal program post- or pre-condition failed. TheAssertionFailurewill 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- ifconditionevaluates to false and the debugging functionality is enabled
-
assertNotNull
If the given object is null, and the debugging functionality is enabled, this method throws anAssertionFailurein 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- ifobjectis 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 anAssertionFailurein 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- ifStringis 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
-