public class Debug extends Object
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.
AssertionFailure
Modifier | Constructor and Description |
---|---|
protected |
Debug()
Protected constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
assertNotNull(Object object)
If the given object is null, and the debugging functionality is enabled, this method throws an
AssertionFailure 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 an
AssertionFailure in order to signal that an internal program post- or pre-condition failed. |
static void |
assertTrue(boolean condition)
If the
condition is NOT true, and the debugging functionality is enabled, this method throws an
AssertionFailure in order to signal that an internal program post- or pre-condition failed. |
static void |
assertTrue(boolean condition,
String message)
If the
condition is NOT true, and the debugging functionality is enabled, this method throws an
AssertionFailure in order to signal that an internal program post- or pre-condition failed. |
static PrintWriter |
getDefaultWriter()
Gets the default writer used for debugging output.
|
static PrintWriter |
getWriter()
Gets the current writer that will used for debugging output.
|
static boolean |
isEnabled()
Checks whether the debugging functionality is enabled or not.
|
static boolean |
isLogging() |
protected static void |
log(String message)
Delegates
Debug.trace() calls to the system logger. |
protected static void |
log(Throwable exception)
Delegates
Debug.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 |
setWriter(Writer writer)
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 |
trace(String message)
Prints the given message string to the current writer if and only if the debugging class functionality is
enabled.
|
static void |
trace(String name,
double[] v) |
static void |
trace(String name,
double[][] v) |
static void |
trace(Throwable exception)
Prints the stack trace for the given exeption to the current writer if and only if the debugging class
functionality is enabled.
|
static void |
traceMemoryUsage()
Calls
traceMemoryUsage(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.
|
protected Debug()
public static boolean isLogging()
public static void setLogging(boolean logging)
public static boolean setEnabled(boolean enabled)
enabled
- if true, debugging functionality will be enabledpublic static boolean isEnabled()
public static PrintWriter getDefaultWriter()
null
if debugging is disabledpublic static PrintWriter getWriter()
null
if debugging is disabledpublic static void setWriter(Writer writer)
writer
- the new writerpublic static void setWriter(OutputStream stream)
stream
- the stream that will be used for debugging outputpublic static void trace(String message)
public static void trace(Throwable exception)
public static void trace(PropertyChangeEvent event)
public static void traceMemoryUsage()
traceMemoryUsage(null)
.traceMemoryUsage(String)
public static void traceMemoryUsage(String label)
label
- an optional label, can be nullpublic static void traceMethodNotImplemented(Class clazz, String methodName)
clazz
- the method's classmethodName
- the method's namepublic static void assertTrue(boolean condition) throws AssertionFailure
condition
is NOT true, and the debugging functionality is enabled, this method throws an
AssertionFailure
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.
condition
- the assert conditionAssertionFailure
- if condition
evaluates to false and the debugging functionality is enabledpublic static void assertTrue(boolean condition, String message) throws AssertionFailure
condition
is NOT true, and the debugging functionality is enabled, this method throws an
AssertionFailure
in order to signal that an internal program post- or pre-condition failed. The
AssertionFailure
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.
condition
- the assert conditionmessage
- an error messageAssertionFailure
- if condition
evaluates to false and the debugging functionality is enabledpublic static void assertNotNull(Object object) throws AssertionFailure
AssertionFailure
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.
object
- the object to test for non-null conditionAssertionFailure
- if object
is null and the debugging functionality is enabledpublic static void assertNotNullOrEmpty(String string) throws AssertionFailure
AssertionFailure
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.
string
- the String to test for non-null and not empty conditionAssertionFailure
- if String
is null or empty and the debugging functionality is enabledprotected static void log(String message)
Debug.trace()
calls to the system logger.message
- the message to be logged.protected static void log(Throwable exception)
Debug.trace()
calls to the system logger.exception
- the exception to be logged.public static void trace(String name, double[][] v)
public static void trace(String name, double[] v)
Copyright © 2014–2015 European Space Agency (ESA). All rights reserved.