Class Debug

  • Direct Known Subclasses:
    JAIDebug

    public class Debug
    extends Object
    The 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:
    AssertionFailure
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Debug()
      Protected constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method 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.
    • Constructor Detail

      • Debug

        protected Debug()
        Protected constructor. Used to prevent object instatiation from this class.
    • 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 null if 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 null if 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()
        Calls traceMemoryUsage(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 class
        methodName - the method's name
      • assertTrue

        public static void assertTrue​(boolean condition)
                               throws AssertionFailure
        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.

        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 - if condition evaluates to false and the debugging functionality is enabled
      • assertTrue

        public static void assertTrue​(boolean condition,
                                      String message)
                               throws AssertionFailure
        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. 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.

        Parameters:
        condition - the assert condition
        message - an error message
        Throws:
        AssertionFailure - if condition evaluates 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 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.

        Parameters:
        object - the object to test for non-null condition
        Throws:
        AssertionFailure - if object is 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 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.

        Parameters:
        string - the String to test for non-null and not empty condition
        Throws:
        AssertionFailure - if String is null or empty and the debugging functionality is enabled
      • log

        protected static void log​(String message)
        Delegates Debug.trace() calls to the system logger.
        Parameters:
        message - the message to be logged.
      • log

        protected static void log​(Throwable exception)
        Delegates Debug.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)