Class Debug
- java.lang.Object
-
- org.esa.snap.core.util.Debug
-
- Direct Known Subclasses:
JAIDebug
public class Debug extends Object
TheDebugas 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 callingDebug.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:
AssertionFailure
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDebug()Protected constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 PrintWritergetDefaultWriter()Gets the default writer used for debugging output.static PrintWritergetWriter()Gets the current writer that will used for debugging output.static booleanisEnabled()Checks whether the debugging functionality is enabled or not.static booleanisLogging()protected static voidlog(String message)DelegatesDebug.trace()calls to the system logger.protected static voidlog(Throwable exception)DelegatesDebug.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 voidsetWriter(Writer writer)Sets 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 voidtrace(String message)Prints the given message string to the current writer if and only if the debugging class functionality is enabled.static voidtrace(String name, double[] v)static voidtrace(String name, double[][] v)static voidtrace(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 voidtraceMemoryUsage()CallstraceMemoryUsage(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.
-
-
-
Method Detail
-
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
public static PrintWriter getDefaultWriter()
Gets the default writer used for debugging output.- Returns:
- the default writer, or
nullif debugging is disabled
-
getWriter
public static PrintWriter 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
public static void setWriter(Writer writer)
Sets the current writer that will be used for debugging output.- Parameters:
writer- the new writer
-
setWriter
public static void setWriter(OutputStream stream)
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
public static void trace(String message)
Prints the given message string to the current writer if and only if the debugging class functionality is enabled.
-
trace
public 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.
-
trace
public 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.
-
traceMemoryUsage
public static void traceMemoryUsage()
CallstraceMemoryUsage(null).- See Also:
traceMemoryUsage(String)
-
traceMemoryUsage
public 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.- Parameters:
label- an optional label, can be null
-
traceMethodNotImplemented
public 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.- Parameters:
clazz- the method's classmethodName- the method's name
-
assertTrue
public static void assertTrue(boolean condition) throws AssertionFailureIf 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
public static void assertTrue(boolean condition, String message) throws AssertionFailureIf 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
public static void assertNotNull(Object object) throws AssertionFailure
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
public static void assertNotNullOrEmpty(String string) throws AssertionFailure
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
protected static void log(String message)
DelegatesDebug.trace()calls to the system logger.- Parameters:
message- the message to be logged.
-
log
protected static void log(Throwable exception)
DelegatesDebug.trace()calls to the system logger.- Parameters:
exception- the exception to be logged.
-
trace
public static void trace(String name, double[][] v)
-
trace
public static void trace(String name, double[] v)
-
-