borland Packages Class Hierarchy jb.util Package
java.lang.Object +----com.borland.jb.util.Diagnostic
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
public static int count = 0A common counter variable used for line numbers for debug output messages. For example,
Diagnostic.out.println(++Diagnostic.count+"\tdebug message");
public static PrintStream out = System.errEnables or disables output of diagnostic messages to
System.err
.
public static boolean outputEnabled = System.getProperty("jb.util.diagnostic", "on").equals("on"))Specifies whether output logging is initially enabled or disabled.
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.
category
removeTraceCategory(java.lang.Object)
public static void check(boolean condition)Checks a condition within a method body.
An IllegalStateException
is thrown if the given condition is false.
condition
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.
public static void check(Object description)Fails if description is not null and display the description.
public static void enableChecking(boolean enable)Enables or disables the checking of conditions in
precondition()
and check()
.
check(boolean)
,
check(boolean, java.lang.Object)
, precondition(boolean)
, precondition(boolean, java.lang.String)
public static void enableOutput(boolean enable)Enables or disables all output of diagnostic messages to
System.err
.
public static void exit(int code)Calls
System.exit(int code)
.
code
public static void fail()Calls
check(false)
to force a failure.
public static void fail(Exception ex)Calls
check(false)
to force a failure but prints the exception message on the stack trace first.
public static void fail(Object description)Causes a check exception if the code reaches an unexpected location.
public static void flush()Flushes the diagnostic out
Stream
buffer.
public static int getTraceLevel()Gets the minimum threshold for trace and warning output.
0
is highest level and +maxint
is lowest level.
setTraceLevel(int)
public static void needException()Used to mark places where an
Exception
is needed.
Upon error, throws an IllegalStateException
.
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.
condition
public static void precondition(boolean condition, String description)Checks a condition. Same as
check(boolean, java.lang.Object)
, but typically placed at the start of the method body.
An IllegalStateException
is thrown if the given condition is false.
condition
description
public static void print(String message)Prints a message to the diagnostic out stream.
message
public static void println(String message)Prints a message to the diagnostic out stream, preceded by a line number (incremented count).
message
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.
message
public static void printStackTrace()Prints a diagnostic stack trace of the current thread to the diagnostic out stream.
public static void printStackTrace(Throwable ex)Prints a diagnostic stack trace of the current thread to the diagnostic out stream. Throws an exception.
public static void removeTraceCategory(Object category)Removes a trace added with
addTraceCategory()
.
category
addTraceCategory(java.lang.Object)
public static void setLogStream(PrintStream log)Explicitly sets the stream for diagnostic messages to be sent to.
log
public static void setTraceLevel(int level)Sets the minimum threshold for trace and warning output.
enableOutput()
instead.
level
0
is highest level and +maxint
is lowest level. Setting this level to -1 effectively turns off traces and warnings.
getTraceLevel()
public static void trace(int level, String description)Outputs a trace if the threshold level is high enough and general output is enabled.
level
0
is highest level and +maxint
is lowest level. Setting this level to -1 effectively turns off traces and warnings.
description
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.
category
level
0
is highest level and +maxint
is lowest level. Setting this level to -1 effectively turns off traces and warnings.
description
addTraceCategory(java.lang.Object)
public static void trace(Object category, String description)Outputs a trace if the category and general output are enabled.
category
description
addTraceCategory(java.lang.Object)
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.
level
0
is highest level and +maxint
is lowest level. Setting this level to -1 effectively turns off traces and warnings.
condition
description
addTraceCategory(java.lang.Object)
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.
category
condition
description
addTraceCategory(java.lang.Object)
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.
category
level
0
is highest level and +maxint
is lowest level. Setting this level to -1 effectively turns off traces and warnings.
condition
description
addTraceCategory(java.lang.Object)
public static void warn(Object category, String description)Outputs a warning if the category and general output are both enabled.
category
description
addTraceCategory(java.lang.Object)