com.borland.primetime.util
Class Debug

java.lang.Object
  |
  +--com.borland.primetime.util.Debug

public class Debug
extends java.lang.Object

Used for testing preconditions and assertions as well as for logging output to help debug the JBuilder product and OpenTools addins. In the final build, the compiler should be told to exclude this class so that all references to it are removed. The compiler command option is: -exclude com.borland.primetime.util.Debug


Field Summary
static int count
           Common counter variable used as 'line numbers' for debug output messages.
static java.io.PrintStream out
          Default output is defined here, initialized to System.err.
 
Constructor Summary
Debug()
           
 
Method Summary
static void addTraceCategory(java.lang.Object category)
           Add tracing and warning for given category of messages.
static void assert(boolean condition)
          Asserts a condition.
static void assert(boolean condition, java.lang.String description)
          Asserts a condition before a method body is run.
static void debugRect(java.awt.Graphics g, int x, int y, int width, int height)
          Paints a color-cycled hashmarked rectangle in the passed bounds for debugging paint messages.
static void enableAssert(boolean enable)
          Enables or disables the checking of conditions in precondition() and check()
static void enableOutput(boolean enable)
          Enables or disables all output of debug messages to System.err.
static void flush()
          Flushes the current "out" stream buffer.
static void print(java.lang.String message)
          Prints a message (without line ending control characters) to the current "out" stream.
static void println(java.lang.String message)
          Prints a message (with line ending control characters) to the current "out" stream.
static void printlnc(java.lang.String message)
          Prints a message to the debug out stream preceded by a line number (incremented count) and a tab character.
static void printStackTrace()
          Prints a debug stack trace of the current thread to the current "out" stream.
static void printStackTrace(java.lang.Throwable ex)
          Prints given exception stack trace to the "out" stream.
static void removeTraceCategory(java.lang.Object category)
           Remove tracing and warning for given category of messages.
static void setLogStream(java.io.PrintStream log)
          Explicitly sets stream for debug messages to be sent to.
static void trace(java.lang.Object category, java.lang.String description)
          Output a trace if the category is enabled and general output is enabled.
static void trace(java.lang.Object category, java.lang.Throwable ex)
          Output a stack trace if the category is enabled and general output is enabled.
static void warn(java.lang.Object category, boolean condition, java.lang.String description)
          Output a warning if the category is enabled, and a condition is true, and general output is enabled.
static void warn(java.lang.Object category, java.lang.String description)
          Outputs a warning if the category is enabled and general output is enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

public static java.io.PrintStream out
Default output is defined here, initialized to System.err.

count

public static int count

Common counter variable used as 'line numbers' for debug output messages.

Example useage: Debug.out.println(++Debug.count+"\tDebug Message");
or for the same output use: Debug.printlnc("Debug Message");

Constructor Detail

Debug

public Debug()
Method Detail

enableOutput

public static void enableOutput(boolean enable)
Enables or disables all output of debug messages to System.err.
Parameters:
enable - True to set "out" to System.err.

setLogStream

public static void setLogStream(java.io.PrintStream log)
Explicitly sets stream for debug messages to be sent to.
Parameters:
log - Set "out" to this PrintStream.

enableAssert

public static void enableAssert(boolean enable)
Enables or disables the checking of conditions in precondition() and check()
Parameters:
enable - True to enable asserts.

assert

public static void assert(boolean condition)
                   throws AssertionException

Asserts a condition. Use this to describe assumed state and parameter values. An AssertionExcpetion is raised if the given condition is not true.

An error here usually indicates a problem with the use of the class.

Parameters:
condition - If false and asserts enabled, throws AssertionException.
Throws:
AssertionException - if asserts enabled and input condition is false.

assert

public static void assert(boolean condition,
                          java.lang.String description)
                   throws AssertionException

Asserts a condition before a method body is run. Use this to describe assumed state and parameter values. A AssertionException is raised if the given condition is not true.

An error here usually indicates a problem with the use of the class.

Parameters:
condition - If false and asserts enabled, throws AssertionException.
description - String to pass as message for AssertionException.
Throws:
AssertionException - if asserts enabled and input condition is false.

addTraceCategory

public static void addTraceCategory(java.lang.Object category)

Add tracing and warning for given category of messages.

Pass in a unique Class or other object that supports a meaningful toString operation. Then when any call to trace or warning is called, the trace is only displayed if an addTraceCategory() call was made with the same category object.

Typical useage is: addTraceCategory(SomeObject.class);

Parameters:
category - Enable tracing of this category.

removeTraceCategory

public static void removeTraceCategory(java.lang.Object category)

Remove tracing and warning for given category of messages.

Pass in a unique Class or other object that supports a meaningful toString operation. Then when any call to trace or warning is called, the trace is only displayed if an addTraceCategory() call was made with the same category object.

Parameters:
category - Remove previously added category to trace.

trace

public static void trace(java.lang.Object category,
                         java.lang.String description)

Output a trace if the category is enabled and general output is enabled.

Typical useage is: trace(SomeObject.class, "doing something to SomeObject now...");

Parameters:
category - Category to which this message belongs.
description - Descriptive text to print if category enabled.

trace

public static void trace(java.lang.Object category,
                         java.lang.Throwable ex)

Output a stack trace if the category is enabled and general output is enabled.

Parameters:
category - Category to which this message belongs.
ex - Source for a stack trace to print if category enabled.

warn

public static void warn(java.lang.Object category,
                        boolean condition,
                        java.lang.String description)

Output a warning if the category is enabled, and a condition is true, and general output is enabled.

Typical useage: warn(SomeObject.class, someObject1.isBroken(), "someObject1 is broken!");

Parameters:
category - Category to which this message belongs.
condition - True if print wanted when category enabled.
description - Descriptive text to print if category enabled.

warn

public static void warn(java.lang.Object category,
                        java.lang.String description)

Outputs a warning if the category is enabled and general output is enabled.

Typical useage: warn(SomeObject.class, "this shouldn't have happened!");

Parameters:
category - Category to which this message belongs.
description - Descriptive text to print if category enabled.

printStackTrace

public static void printStackTrace()
Prints a debug stack trace of the current thread to the current "out" stream.

printStackTrace

public static void printStackTrace(java.lang.Throwable ex)
Prints given exception stack trace to the "out" stream.
Parameters:
ex - Source for a stack trace to print.

println

public static void println(java.lang.String message)
Prints a message (with line ending control characters) to the current "out" stream.
Parameters:
message - Text to be output.

print

public static void print(java.lang.String message)
Prints a message (without line ending control characters) to the current "out" stream.
Parameters:
message - Text to be output.

printlnc

public static void printlnc(java.lang.String message)

Prints a message to the debug out stream preceded by a line number (incremented count) and a tab character. This is used to track repetetive operations (like painting algorhythms).

Typical useage: printlnc("SomeObject.paint() called");

Parameters:
message - Text to be output.

flush

public static void flush()
Flushes the current "out" stream buffer.

debugRect

public static void debugRect(java.awt.Graphics g,
                             int x,
                             int y,
                             int width,
                             int height)

Paints a color-cycled hashmarked rectangle in the passed bounds for debugging paint messages. As subsequent calls are made to debugRect, the hash direction of the debug rectangle will alternate directions, cycle through colors, and vary in hash-mark spacing. This is to allow a viewer to distinguish between different and often repetitive calls to debugRect.

Typical useage: public void paint(Graphics g) { Rectangle clip = g.getClipBounds(); Debug.debugRect(g, clip.x, clip.y, clip.width, clip.height); }

Parameters:
g - Graphics object to paint with.
x - Left bound of rectangle.
y - Top bound of rectangle.
width - Width of rectangle.
height - Height of rectangle.