d
Class p

java.lang.Object
  extended by d.p

public final class p
extends Object

This class provides static methods which send output to a PrintWriter. You can use the various s methods to simply print out primitive types or Strings, or print out complete Object states.

The getPrintWriter()/setPrintWriter(java.io.PrintWriter) methods are the accessor/mutator for the PrintWriter used. The default PrintWriter wraps System.out.

This class was designed to require as little typing as possible to use. In particular, all public names (package, class, and method) are lower case and have the minmal length (one char each). So, you can avoid import statements and easily invoke all methods using their fully qualified form. Here are some typical uses:


        d.p.s();        // prints a blank line
        ...
        d.p.s("reached point #1");      // use to note that your program reached a certain point
        ...
        d.p.s(i);       // i is an int, previously defined and assigned, that you now want to print
        ...
        d.p.s("l = " + l);      // print out some descriptive text followed by some long value
        ...
        OneOfMyTypes myObject = new OneOfMyTypes();
        d.p.s("Complete state of OneOfMyTypes", myObject);      // print out an object's fields
 

Mnemonic: the package name d stands for debug; the class name p stands for PrintWriter; the methods named s stand for send.

This class is multithread safe.

Author:
Brent Boyer

Nested Class Summary
static class p.UnitTest
          See the Overview page of the project's javadocs for a general description of this unit test class.
 
Field Summary
private static PrintWriter pw
          The PrintWriter used by the s methods.
 
Constructor Summary
private p()
          This private constructor suppresses the default (public) constructor, ensuring non-instantiability.
 
Method Summary
static PrintWriter getPrintWriter()
          Accessor for pw.
private static void onShutdown()
          Performs actions that should only be done before the JVM shuts down, such as flushing pw.
static void s()
          Prints a blank line.
static void s(boolean b)
          Prints b on a line.
static void s(char c)
          Prints c on a line.
static void s(CharSequence charSequence)
          Prints charSequence on a line.
static void s(double d)
          Prints d on a line.
static void s(long l)
          Prints l on a line.
static void s(String label, Object obj)
          Prints out label followed by obj.
static void setPrintWriter(PrintWriter pw)
          Mutator for pw.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pw

private static PrintWriter pw
The PrintWriter used by the s methods.

Constructor Detail

p

private p()
This private constructor suppresses the default (public) constructor, ensuring non-instantiability.

Method Detail

getPrintWriter

public static PrintWriter getPrintWriter()
Accessor for pw.


setPrintWriter

public static void setPrintWriter(PrintWriter pw)
                           throws IllegalArgumentException
Mutator for pw. Before the existing PrintWriter is swapped out, it is first flushed.

This class is typically used for debugging. In this context, the I/O performance of pw is less important than its reliability. Therefore, it is highly recommended that the pw arg be set to autoflush, since otherwise have seen problems with output not appearing in a timely manner or at all.

Throws:
IllegalArgumentException - if pw == null; pw is in the error state

s

public static void s()
              throws IllegalStateException
Prints a blank line.

Throws:
IllegalStateException - if pw is in the error state

s

public static void s(boolean b)
              throws IllegalStateException
Prints b on a line.

Throws:
IllegalStateException - if pw is in the error state

s

public static void s(char c)
              throws IllegalStateException
Prints c on a line.

Throws:
IllegalStateException - if pw is in the error state

s

public static void s(long l)
              throws IllegalStateException
Prints l on a line. It should be used to print out any integral-type primitive (i.e. byte, short, int, long).

Throws:
IllegalStateException - if pw is in the error state

s

public static void s(double d)
              throws IllegalStateException
Prints d on a line. It should be used to print out any floating point-type primitive (i.e. float, double).

Throws:
IllegalStateException - if pw is in the error state

s

public static void s(CharSequence charSequence)
              throws IllegalStateException
Prints charSequence on a line.

Throws:
IllegalStateException - if pw is in the error state

s

public static void s(String label,
                     Object obj)
              throws IllegalStateException
Prints out label followed by obj. Both args are optional (either may be null).

If label is non-null, it is printed followed by ": " on one line. Next, the complete state of obj is printed using ObjectState.

Throws:
IllegalStateException - if pw is in the error state

onShutdown

private static void onShutdown()
Performs actions that should only be done before the JVM shuts down, such as flushing pw.