com.tensegrity.generic.util
Class Debug

java.lang.Object
  extended bycom.tensegrity.generic.util.Debug

public final class Debug
extends java.lang.Object

Class Debug holds the global environment settings and provides a few utility methods that are used throughout all of the framework code.

Several flags are defined that apply to debug tracing (outputs), which makes handling the different trace outputs easier. To begin, there is a global flag DebugMode.DEBUG, which indicates that you want to build a debug version or alternatively a release version of the software. Because of the final declaration, the compiler can perform some optimizations on the compiled code, so that a release class file is smaller than the debug class file. Secondly, the debug tracing outputs are categorized so that it becomes possible to turn off a complete category of traces. For example, the DISPLAY_THROWABLES flag can be checked while used in combination with try ... catch statements like the following code segment:

 try
 {
     ...
 }
 catch( Throwable throwable )
 {
     if( Debug.DISPLAY_THROWABLES )
     {
         throwable.printStackTrace()
     }
 }
 
If a flag is used in this way in all of the classes, you can turn on and off all of the trace outputs that are part of a Throwable catch. Another example is the DISPLAY_DEBUG_INFOS category, which should be used in this way:
 if( Debug.DISPLAY_DEBUG_INFOS )
 {
     System.out.println("do some tracings here ...")
 }
 
By using this flag you can turn on and off all tracings that belongs to the new category. Lastly, you can optionally define a flag in each class, giving you the possibility to turn on and off the trace outputs for that specific class. Remember that there can be a lot of traces to an output stream and that you may have to search for specific trace information while debugging. Using a combination of trace output flags, you can trace specific information by turning on useful categories and turning off those that are not needed. The if statement therefore looks like this:
 if( Debug.DISPLAY_DEBUG_INFOS )
 {
     System.out.println("do some tracings here ...")
 }
 
The trace output flags defined in specific classes should be set to false by default.

Class Debug provides static methods only and no public constructors.

IMPORTANT NOTE: Always keep in mind that the global DebugMode.DEBUG flag will disable all other global debugging info.

Version:
$Id: Debug.java,v 1.85 2006/05/09 09:30:21 MichaelKegel Exp $
Author:
M.Kegel, S.Rutz

Nested Class Summary
static class Debug.OnlyDoLastTriggered
           This class uses the SwingUtilities.invokeLater(java.lang.Runnable) method to ensure that a piece of code is only run once after all events have been processed.
 
Field Summary
static boolean ALLOW_DYNAMIC_EXCEPTIONS
          Global flag to allow throwing of DynamicExceptions
static boolean ASSERT_THROWS_EXCEPTION
          Determines whether to throw an assertion exception in case a check failed.
static boolean DISPLAY_DEBUG_INFOS
          global flag to turn on/turn off all tracings which are needed for debugging purposes This flag is dynamic and subject to change during runtime.
static boolean DISPLAY_DEPRECATIONS
          global flag to turn on/turn off all traces related to deprecations.
static boolean DISPLAY_ERRORS
          global flag to turn on/turn off all tracings related to errors.
static boolean DISPLAY_OBSOLETE_INFO
          global flag to turn on/turn off all traces related to obsolete data, method calls and such.
static boolean DISPLAY_STATIC_INFOS
          global flag to turn on/off static traces
static boolean DISPLAY_THROWABLES
          global flag to turn on/turn off all tracings related to throwables This flag is dynamic and subject to change during runtime.
static boolean DISPLAY_WARNINGS
          global flag to turn on/turn off all tracings related to warnings.
static boolean DO_ASSERT
          Globally enables or disables assertion checks.
 
Method Summary
static java.lang.String bits(int value)
          Returns a string representation of a bit pattern.
static java.lang.String createIndentation(java.lang.String string, char blockStart, char blockEnd)
          Creates an indentation in the given string by using the given characters to increase or decrease indentation per line.
static java.lang.String getMaskInfo(int mask, int[] flags, java.lang.String[] flagNames)
          Returns a human readable string containing the ids of all flags that are set in the given mask.
static java.lang.String getThrowableStackString(java.lang.Throwable t)
          Returns a string containing the stack trace
static java.lang.String getThrowableStackString(java.lang.Throwable t, int maxLineCount)
          Returns a string containing the stack trace
static java.lang.String hashcode(java.lang.Object object)
          Prints an object hashcode in a standard way.
static java.lang.String hexStr(int i, int len)
          Returns a hex string for the given integer with at least the length len
static boolean isPartOfStackTrace(java.lang.String pattern)
          Returns true, if the current stack trace contains the given pattern.
static java.lang.String list2String(java.util.List list)
          Returns a String that represents the content of the List given by list.
static java.lang.String makeIndent(int level)
          Returns a String that can be used as an indent when displaying a hierarchy.
static void printBlueStackTrace()
          Displays a blue stack trace, used to check from where a method is called.
static void printBlueStackTrace(int maxLineCount)
          Displays a blue stack trace, used to check from where a method is called.
static void printBlueStackTrace(java.lang.Throwable t, int maxLineCount)
          Displays a blue stack trace, used to check from where a method is called.
static void printDebugInfo(java.lang.String message)
          Prints a debug info message in a standard way.
static void printDeprecation(java.lang.String message)
          Prints a deprecation message in a standard way.
static void printError(java.lang.String message)
          Prints an error in a standard way.
static void printMap(java.util.Map map)
          Prints a map.
static void printMapHashcodes(java.util.Map map)
          Prints a map in hashcode format to stderr.
static void printMapSorted(java.util.Map map)
          Prints a map alphabetically sorted.
static void printMapSortedHashcodes(java.util.Map map)
          Prints a map alphabetically sorted and just print the hashcodes of the keys and values.
static void printObsoleteInfo(java.lang.String message)
          Prints a obsolete info message in a standard way.
static void printSet(java.util.Set set)
          Method printSet prints all elements of the parameter set to System.err.
static void printStaticInfo(java.lang.String message)
           
static void printThrowable(java.lang.Throwable throwable)
          Prints a throwable in a standard way.
static void printWarning(java.lang.String message)
          Prints a warning in a standard way.
static void printWarning(java.lang.String message, boolean toStdOut)
          Prints a warning in a standard way.
static boolean safeEquals(java.lang.Object obj1, java.lang.Object obj2)
          Deprecated. Use Comparison.safeEquals(Object, Object) instead!
static boolean safeEqualsIgnoreCase(java.lang.String str1, java.lang.String str2)
          Deprecated. Use Comparison.safeEqualsIgnoreCase(String, String) instead!
static int safeHashCode(java.lang.Object obj)
          Deprecated. Use Comparison.safeHashCode(Object) instead!
static java.lang.String strReplace(java.lang.String string, java.lang.String token, java.lang.String replaceString)
          String replace function, replaces all occurances of the token in the string with another string (Only necessary, because String.replaceAll( java.lang.String, java.lang.String) is not implemented in jdk1.3).
static java.lang.String[] strSplit(java.lang.String str, java.lang.String delimiters)
          Splits a string into an array of strings using the given delimiters.
static java.lang.String toIndentedString(java.lang.String str, int level)
          Returns a string with an indentation after each linefeed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DO_ASSERT

public static final boolean DO_ASSERT
Globally enables or disables assertion checks. DEBUG should be set to true for assertion to come up.

See Also:
Constant Field Values

ASSERT_THROWS_EXCEPTION

public static final boolean ASSERT_THROWS_EXCEPTION
Determines whether to throw an assertion exception in case a check failed. If the field is set to false then the program is aborted with exit(1)

See Also:
Constant Field Values

ALLOW_DYNAMIC_EXCEPTIONS

public static final boolean ALLOW_DYNAMIC_EXCEPTIONS
Global flag to allow throwing of DynamicExceptions

See Also:
Constant Field Values

DISPLAY_THROWABLES

public static final boolean DISPLAY_THROWABLES
global flag to turn on/turn off all tracings related to throwables This flag is dynamic and subject to change during runtime.

See Also:
Constant Field Values

DISPLAY_WARNINGS

public static final boolean DISPLAY_WARNINGS
global flag to turn on/turn off all tracings related to warnings. This flag is dynamic and subject to change during runtime.

See Also:
Constant Field Values

DISPLAY_ERRORS

public static final boolean DISPLAY_ERRORS
global flag to turn on/turn off all tracings related to errors. This flag is dynamic and subject to change during runtime.

See Also:
Constant Field Values

DISPLAY_DEBUG_INFOS

public static final boolean DISPLAY_DEBUG_INFOS
global flag to turn on/turn off all tracings which are needed for debugging purposes This flag is dynamic and subject to change during runtime.

See Also:
Constant Field Values

DISPLAY_OBSOLETE_INFO

public static final boolean DISPLAY_OBSOLETE_INFO
global flag to turn on/turn off all traces related to obsolete data, method calls and such.

See Also:
Constant Field Values

DISPLAY_DEPRECATIONS

public static final boolean DISPLAY_DEPRECATIONS
global flag to turn on/turn off all traces related to deprecations.

See Also:
Constant Field Values

DISPLAY_STATIC_INFOS

public static final boolean DISPLAY_STATIC_INFOS
global flag to turn on/off static traces

See Also:
Constant Field Values
Method Detail

printObsoleteInfo

public static final void printObsoleteInfo(java.lang.String message)
Prints a obsolete info message in a standard way.

Parameters:
message - the debug info message to print.

printDeprecation

public static final void printDeprecation(java.lang.String message)
Prints a deprecation message in a standard way.

Parameters:
message - the deprecation message to print.

printDebugInfo

public static final void printDebugInfo(java.lang.String message)
Prints a debug info message in a standard way.

Parameters:
message - the debug info message to print.

printThrowable

public static final void printThrowable(java.lang.Throwable throwable)
Prints a throwable in a standard way.

Parameters:
throwable - the throwable to print.

printError

public static final void printError(java.lang.String message)
Prints an error in a standard way.

Parameters:
message - the error message to print.

printWarning

public static final void printWarning(java.lang.String message)
Prints a warning in a standard way.

Parameters:
message - the warning message to print.

printWarning

public static final void printWarning(java.lang.String message,
                                      boolean toStdOut)
Prints a warning in a standard way.

Parameters:
message - the warning message to print.
toStdOut - true, to print to out instead of err

printStaticInfo

public static final void printStaticInfo(java.lang.String message)

printMap

public static final void printMap(java.util.Map map)
Prints a map.

Parameters:
map - the map to print.

printMapHashcodes

public static final void printMapHashcodes(java.util.Map map)
Prints a map in hashcode format to stderr.

Parameters:
map - the map to print.

printSet

public static final void printSet(java.util.Set set)
Method printSet prints all elements of the parameter set to System.err.

Parameters:
set - the instance of Set to print out.

printMapSorted

public static final void printMapSorted(java.util.Map map)
Prints a map alphabetically sorted.

Parameters:
map - the map to print.

printMapSortedHashcodes

public static final void printMapSortedHashcodes(java.util.Map map)
Prints a map alphabetically sorted and just print the hashcodes of the keys and values.

Parameters:
map - the map to print.

hashcode

public static final java.lang.String hashcode(java.lang.Object object)
Prints an object hashcode in a standard way.

Parameters:
object - the Object to retirive the hashcode for.
Returns:
the hashcode for the given object in a standard way.

bits

public static final java.lang.String bits(int value)
Returns a string representation of a bit pattern.

Parameters:
value - the value to return a bit representation for.
Returns:
a string representation of a bit pattern.

makeIndent

public static final java.lang.String makeIndent(int level)
Returns a String that can be used as an indent when displaying a hierarchy. The int given by level represents the level of indentation.

Parameters:
level - the level of indentation
Returns:
String the indent

list2String

public static final java.lang.String list2String(java.util.List list)
Returns a String that represents the content of the List given by list.

Parameters:
list - the List to convert into a String representation
Returns:
String the content of the given List

printBlueStackTrace

public static final void printBlueStackTrace()
Displays a blue stack trace, used to check from where a method is called. It is printed out to the stdout instead of stderr, to distinguish it from real exceptions


printBlueStackTrace

public static final void printBlueStackTrace(int maxLineCount)
Displays a blue stack trace, used to check from where a method is called. It is printed out to the stdout instead of stderr, to distinguish it from real exceptions

Parameters:
maxLineCount - The maximum number of rows to display

printBlueStackTrace

public static final void printBlueStackTrace(java.lang.Throwable t,
                                             int maxLineCount)
Displays a blue stack trace, used to check from where a method is called. It is printed out to the stdout instead of stderr, to distinguish it from real exceptions

Parameters:
t - The throwable to print the stack trace of
maxLineCount - The maximum number of rows to display

isPartOfStackTrace

public static final boolean isPartOfStackTrace(java.lang.String pattern)
Returns true, if the current stack trace contains the given pattern. Use this function only for Debugging purpose!

Parameters:
pattern - The item to look for in the stack trace
Returns:
true, if the current stack trace contains the given pattern.

getThrowableStackString

public static java.lang.String getThrowableStackString(java.lang.Throwable t)
Returns a string containing the stack trace

Parameters:
t - The throwable to get the stack from
Returns:
A string containing the stack trace

getThrowableStackString

public static java.lang.String getThrowableStackString(java.lang.Throwable t,
                                                       int maxLineCount)
Returns a string containing the stack trace

Parameters:
t - The throwable to get the stack from
maxLineCount - The maximum number of line to generate
Returns:
A string containing the stack trace

toIndentedString

public static java.lang.String toIndentedString(java.lang.String str,
                                                int level)
Returns a string with an indentation after each linefeed

Parameters:
str - The string to change
level - The level of indentation to apply
Returns:
The indented string

createIndentation

public static java.lang.String createIndentation(java.lang.String string,
                                                 char blockStart,
                                                 char blockEnd)
Creates an indentation in the given string by using the given characters to increase or decrease indentation per line.

Parameters:
string - The string to modify
blockStart - When this char occurs in a line, the FOLLOWING lines will be indented.
blockEnd - When this char occurs in a line, the indentation will be decreased, starting in this line.
Returns:
The indented string

strReplace

public static java.lang.String strReplace(java.lang.String string,
                                          java.lang.String token,
                                          java.lang.String replaceString)
String replace function, replaces all occurances of the token in the string with another string (Only necessary, because String.replaceAll( java.lang.String, java.lang.String) is not implemented in jdk1.3).

Parameters:
string - The original string
token - The substring to look for
replaceString - The string to replace the token with
Returns:
The changed string

strSplit

public static final java.lang.String[] strSplit(java.lang.String str,
                                                java.lang.String delimiters)
Splits a string into an array of strings using the given delimiters.

Parameters:
str - The string to split
delimiters - The delimiters
Returns:
An array containing the parts

hexStr

public static java.lang.String hexStr(int i,
                                      int len)
Returns a hex string for the given integer with at least the length len

Parameters:
i - The integer to represent
len - The minimum length of the string
Returns:
The hex string

getMaskInfo

public static final java.lang.String getMaskInfo(int mask,
                                                 int[] flags,
                                                 java.lang.String[] flagNames)
Returns a human readable string containing the ids of all flags that are set in the given mask.

Parameters:
mask - the mask to examine
flags - the flag values to look for
flagNames - the names to return in the string
Returns:
a human readable string containing the ids of all flags that are set in the given mask.

safeEquals

public static final boolean safeEquals(java.lang.Object obj1,
                                       java.lang.Object obj2)
Deprecated. Use Comparison.safeEquals(Object, Object) instead!

Checks if the two given objects are equal, includes a check for null values

Parameters:
obj1 - The first object
obj2 - The second object
Returns:
True, if the two objects are equal

safeEqualsIgnoreCase

public static final boolean safeEqualsIgnoreCase(java.lang.String str1,
                                                 java.lang.String str2)
Deprecated. Use Comparison.safeEqualsIgnoreCase(String, String) instead!

Checks if the two given strings are equal (ignoring case), includes a check for null values

Parameters:
str1 - The first string
str2 - The second string
Returns:
True, if the two strings are equal

safeHashCode

public static final int safeHashCode(java.lang.Object obj)
Deprecated. Use Comparison.safeHashCode(Object) instead!

Returns the hashcode of the object. If the object is null, 0 is returned.

Parameters:
obj - The object to get the hashcode of
Returns:
The hashcode of the object


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.