import java.io.PrintWriter;


/**
 *  This class is a collection of functions for printing 
 *  debugging info (i.e., you can turn it on and off 
 *  globally).
 *
 *  <p>
 *  Use this class in place of System.out.println like so:
 *  <blockquote>
 *    <tt>Debug.println(foo);</tt>
 *  </blockquote>
 *  where foo is a primitive type or an Object.
 *
 *  <p>
 *  You could do this without making every function
 *  static by expecting users to write:
 *  <blockquote>
 *    <tt>new Debug().println(foo);</tt>
 *  </blockquote>
 *  but I have found C++ programmers have problems with
 *  this style.
 *
 *  <p>
 *  Objects to be printed should implement the function 
 *  toString() in a meaningful way.
 */
public class Debug
{
    //////////////////////////////////////////////////////////////
    // state
    private static PrintWriter ourWriter = new PrintWriter(System.out);
    private static boolean ourShouldDebug = false;


    //////////////////////////////////////////////////////////////
    // constructors
    public static void setWriter (PrintWriter out)
    {
        ourWriter = out;
    }

    //////////////////////////////////////////////////////////////
    // public methods
    public static void turnOn ()
    {
        ourShouldDebug = true;
    }
    
    public static void turnOff ()
    {
        ourShouldDebug = false;
    }


    // yuck :(
    public static void print (boolean b)
    {
        if (ourShouldDebug) { ourWriter.print(b); ourWriter.flush(); }
    }

    public static void print (char c)
    {
        if (ourShouldDebug) { ourWriter.print(c); ourWriter.flush(); }
    }

    public static void print (int i)
    {
        if (ourShouldDebug) { ourWriter.print(i); ourWriter.flush(); }
    }

    public static void print (long l)
    {
        if (ourShouldDebug) { ourWriter.print(l); ourWriter.flush(); }
    }

    public static void print (float f)
    {
        if (ourShouldDebug) { ourWriter.print(f); ourWriter.flush(); }
    }

    public static void print (double d)
    {
        if (ourShouldDebug) { ourWriter.print(d); ourWriter.flush(); }
    }

    public static void print (String s)
    {
        if (ourShouldDebug) { ourWriter.print(s); ourWriter.flush(); }
    }

    public static void print (Object o)
    {
        if (ourShouldDebug) { ourWriter.print(o); ourWriter.flush(); }
    }


    // yuck yuck :(
    public static void println ()
    {
        if (ourShouldDebug) { ourWriter.println(); ourWriter.flush(); }
    }

    public static void println (boolean b)
    {
        if (ourShouldDebug) { ourWriter.println(b); ourWriter.flush(); }
    }

    public static void println (char c)
    {
        if (ourShouldDebug) { ourWriter.println(c); ourWriter.flush(); }
    }

    public static void println (int i)
    {
        if (ourShouldDebug) { ourWriter.println(i); ourWriter.flush(); }
    }

    public static void println (long l)
    {
        if (ourShouldDebug) { ourWriter.println(l); ourWriter.flush(); }
    }

    public static void println (float f)
    {
        if (ourShouldDebug) { ourWriter.println(f); ourWriter.flush(); }
    }

    public static void println (double d)
    {
        if (ourShouldDebug) { ourWriter.println(d); ourWriter.flush(); }
    }

    public static void println (String s)
    {
        if (ourShouldDebug) { ourWriter.println(s); ourWriter.flush(); }
    }

    public static void println (Object o)
    {
        if (ourShouldDebug) { ourWriter.println(o); ourWriter.flush(); }
    }
}
