borland Packages  Class Hierarchy  jb.util Package 

Diagnostic class

java.lang.Object
   +----com.borland.jb.util.Diagnostic

About the Diagnostic class

Variables  Properties  Methods  

The Diagnostic component collects useful diagnostic functions for debugging program flow and output.

All calls to Diagnostic methods with a void return type can be removed from the compiled classes by using the compiler's exclude class option:

-exclude com.borland.jb.util.Diagnostic


Diagnostic variables

Variables implemented in this class

Diagnostic properties

*Read-only properties **Write-only properties

Properties implemented in java.lang.Object

Diagnostic methods

Methods implemented in this class

Methods implemented in java.lang.Object


Diagnostic variables

count

  public static int count = 0
A common counter variable used for line numbers for debug output messages. For example,
Diagnostic.out.println(++Diagnostic.count+"\tdebug message");

out

  public static PrintStream out = System.err
Enables or disables output of diagnostic messages to System.err.

outputEnabled

  public static boolean outputEnabled = System.getProperty("jb.util.diagnostic", "on").equals("on"))
Specifies whether output logging is initially enabled or disabled.

Diagnostic methods

addTraceCategory(java.lang.Object)

  public static void addTraceCategory(Object category)
A category-based tracing or warning method.

To set up a category-based tracing or warning, pass in a unique String, Class or other object that supports a meaningful toString operation. When a call to a trace or warn method that takes a category is made (for example, trace(Object category, String description)), the trace is displayed if an addTraceCategory() call was made with the same category object.

Parameters:

category
The category object.

See also: removeTraceCategory(java.lang.Object)

check(boolean)

  public static void check(boolean condition)
Checks a condition within a method body.

An IllegalStateException is thrown if the given condition is false.

Parameters:

condition
The boolean condition.

check(boolean, java.lang.Object)

  public static void check(boolean condition, Object description)
Checks a condition within a method body.

Use this method to describe assumed results and state after internal operations.

A check is raised if the given condition is not true. An error here usually indicates an internal problem with the class.

enableChecking(boolean)

  public static void enableChecking(boolean enable)
Enables or disables the checking of conditions in precondition() and check().

See also: check(boolean), check(boolean, java.lang.Object), precondition(boolean), precondition(boolean, java.lang.String)

enableOutput(boolean)

  public static void enableOutput(boolean enable)
Enables or disables all output of diagnostic messages to System.err.

exit(int)

  public static void exit(int code)
Calls System.exit(int code).

Parameters:

code
The method body to exit.

fail()

  public static void fail()
Calls check(false) to force a failure.

fail(java.lang.Exception)

  public static void fail(Exception ex)
Calls check(false) to force a failure but prints the exception message on the stack trace first.

fail(java.lang.Object)

  public static void fail(Object description)
Causes a check exception if the code reaches an unexpected location.

flush()

  public static void flush()
Flushes the diagnostic out Stream buffer.

getTraceLevel()

  public static int getTraceLevel()
Gets the minimum threshold for trace and warning output. 0 is highest level and +maxint is lowest level.

See also: setTraceLevel(int)

needException()

  public static void needException()
Used to mark places where an Exception is needed.

Upon error, throws an IllegalStateException.

precondition(boolean)

  public static void precondition(boolean condition)
Checks a condition. Same as check(boolean), but typically placed at the start of the method body.

An IllegalStateException is thrown if the given condition is false.

Parameters:

condition
The boolean condition, either true or false.

precondition(boolean, java.lang.String)

  public static void precondition(boolean condition, String description)
Checks a condition. Same as check(boolean, java.lang.String), but typically placed at the start of the method body.

An IllegalStateException is thrown if the given condition is false.

Parameters:

condition
The boolean condition, either true or false.
description
The description to print.

print(java.lang.String)

  public static void print(String message)
Prints a message to the diagnostic out stream.

Parameters:

message
The message to print.

println(java.lang.String)

  public static void println(String message)
Prints a message to the diagnostic out stream, preceded by a line number (incremented count).

Parameters:

message
The message to print.

printlnc(java.lang.String)

  public static void printlnc(String message)

Prints a message to the diagnostic out stream, preceded by a line number (incremented count) and a tab character.

Parameters:

message
The message to print.

printStackTrace()

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

printStackTrace(java.lang.Throwable)

  public static void printStackTrace(Throwable ex)
Prints a diagnostic stack trace of the current thread to the diagnostic out stream. Throws an exception.

removeTraceCategory(java.lang.Object)

  public static void removeTraceCategory(Object category)
Removes a trace added with addTraceCategory().

Parameters:

category
The category object.

See also: addTraceCategory(java.lang.Object)

setLogStream(java.io.PrintStream)

  public static void setLogStream(PrintStream log)
Explicitly sets the stream for diagnostic messages to be sent to.

Parameters:

log
The stream for messages to be sent to.

setTraceLevel(int)

  public static void setTraceLevel(int level)
Sets the minimum threshold for trace and warning output.

Note: This does not affect direct access to 'out', nor does it affect output in the checking functions. Use enableOutput() instead.

Parameters:

level
The trace level. 0 is highest level and +maxint is lowest level. Setting this level to -1 effectively turns off traces and warnings.

See also: getTraceLevel()

trace(int, java.lang.String)

  public static void trace(int level, String description)
Outputs a trace if the threshold level is high enough and general output is enabled.

Parameters:

level
The trace level. 0 is highest level and +maxint is lowest level. Setting this level to -1 effectively turns off traces and warnings.
description
The string to trace.

trace(java.lang.Object, int, java.lang.String)

  public static void trace(Object category, int level, String description)
Outputs a trace if the category and general output are both enabled, and the threshold level is high enough.

Parameters:

category
The category object to trace.
level
The trace level. 0 is highest level and +maxint is lowest level. Setting this level to -1 effectively turns off traces and warnings.
description
The string to trace.

See also: addTraceCategory(java.lang.Object)

trace(java.lang.Object, java.lang.String)

  public static void trace(Object category, String description)
Outputs a trace if the category and general output are enabled.

Parameters:

category
The category object to trace.
description
The string to trace.

See also: addTraceCategory(java.lang.Object)

warn(int, boolean, java.lang.String)

  public static void warn(int level, boolean condition, String description)
Outputs a warning if the threshold level is high enough, the boolean condition is true, and general output is enabled.

Parameters:

level
The trace level. 0 is highest level and +maxint is lowest level. Setting this level to -1 effectively turns off traces and warnings.
condition
The boolean condition, either true or false.
description
The string to trace.

See also: addTraceCategory(java.lang.Object)

warn(java.lang.Object, boolean, java.lang.String)

  public static void warn(Object category, boolean condition, String description)
Outputs a warning if the category object is enabled, the boolean condition is true, and general output is enabled.

Parameters:

category
The category object to trace.
condition
The boolean condition, either true or false.
description
The string to trace.

See also: addTraceCategory(java.lang.Object)

warn(java.lang.Object, int, boolean, java.lang.String)

  public static void warn(Object category, int level, boolean condition, String description)
Outputs a warning if the category object is enabled, the boolean condition is true, and general output is enabled.

Parameters:

category
The category object to trace.
level
The trace level. 0 is highest level and +maxint is lowest level. Setting this level to -1 effectively turns off traces and warnings.
condition
The boolean condition, either true or false.
description
The string to trace.

See also: addTraceCategory(java.lang.Object)

warn(java.lang.Object, java.lang.String)

  public static void warn(Object category, String description)
Outputs a warning if the category and general output are both enabled.

Parameters:

category
The category object to trace.
description
The string to trace.

See also: addTraceCategory(java.lang.Object)