summaryrefslogtreecommitdiff
path: root/src/main/java/io/devnulllabs/openjava/tools/DebugOut.java
blob: 8b29a45b0d108277cafd26a4f4f600e44cbbdf43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * DebugOut.java 1.0
 *
 * This class manages imported classes with statement
 * "import foo.Bar;" and "import foo.*;".
 *
 * Apr 7, 1998
 *
 * @version 1.0 last updated: Apr 7, 1998
 * @author  Michiaki Tatsubori
 */
package io.devnulllabs.openjava.tools;


import java.io.PrintStream;


/**
 * The DebugOut class is used to print something in debugging.
 * No instance should be allocate and this class should be used statically.
 *
 * <p>This class implements most methods of public printing methods
 * found in java.io.PrintWriter, as static methods.
 *
 * @version     1.0a1, 98/04/10
 * @author    Michiaki Tatsubori
 * @since    JDK1.1
 * @see         io.devnulllabs.openjava.ptree.NonLeaf
 */
public final class DebugOut
{
    private static int debugLevel = 0;

    public static void setDebugLevel( int level ) {
    debugLevel = level;
    }

    /**
     * for debug
     */
    protected static PrintStream out = System.err;

    /** Flush the stream. */
    public static void flush() {
        if (debugLevel > 2)  out.flush();
    }

    /** Close the stream. */
    public static void close() {
        if (debugLevel > 2)  out.close();
    }

    /**
     * Flush the stream and check its error state.  Errors are cumulative;
     * once the stream encounters an error, this routine will return true on
     * all successive calls.
     *
     * @return True if the print stream has encountered an error, either on
     * the underlying output stream or during a format conversion.
     */
    public static boolean checkError() {
    return out.checkError();
    }

    /* Methods that do not terminate lines */

    /** Print a boolean. */
    public static void print( boolean b ) {
        if (debugLevel > 2)  out.print( b );
    }

    /** Print a character. */
    public static void print( char c ) {
        if (debugLevel > 2)  out.print( c );
    }

    /** Print an integer. */
    public static void print( int i ) {
        if (debugLevel > 2)  out.print( i );
    }

    /** Print a long. */
    public static void print( long l ) {
        if (debugLevel > 2)  out.print( l );
    }

    /** Print a float. */
    public static void print( float f ) {
        if (debugLevel > 2)  out.print( f );
    }

    /** Print a double. */
    public static void print( double d ) {
        if (debugLevel > 2)  out.print( d );
    }

    /** Print an array of chracters. */
    public static void print( char s[] ) {
        if (debugLevel > 2)  out.print( s );
    }

    /** Print a String. */
    public static void print( String s ) {
        if (debugLevel > 2)  out.print( s );
    }

    /** Print an object. */
    public static void print( Object obj ) {
        if (debugLevel > 2)  out.print( obj );
    }

    /* Methods that do terminate lines */

    /** Finish the line. */
    public static void println() {
        if (debugLevel > 2)  out.println();
    }

    /** Print a boolean, and then finish the line. */
    public static void println( boolean x ) {
        if (debugLevel > 2)  out.println( x );
    }

    /** Print a character, and then finish the line. */
    public static void println( char x ) {
        if (debugLevel > 2)  out.println( x );
    }

    /** Print an integer, and then finish the line. */
    public static void println( int x ) {
        if (debugLevel > 2)  out.println( x );
    }

    /** Print a long, and then finish the line. */
    public static void println( long x ) {
        if (debugLevel > 2)  out.println( x );
    }

    /** Print a float, and then finish the line. */
    public static void println( float x ) {
        if (debugLevel > 2)  out.println( x );
    }

    /** Print a double, and then finish the line. */
    public static void println( double x ) {
        if (debugLevel > 2)  out.println( x );
    }

    /** Print an array of characters, and then finish the line. */
    public static void println( char x[] ) {
        if (debugLevel > 2)  out.println( x );
    }

    /** Print a String, and then finish the line. */
    public static void println( String x ) {
        if (debugLevel > 2)  out.println( x );
    }

    /** Print an Object, and then finish the line. */
    public static void println( Object x ) {
        if (debugLevel > 2)  out.println( x );
    }

}