-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebug.java
More file actions
65 lines (59 loc) · 1.37 KB
/
Debug.java
File metadata and controls
65 lines (59 loc) · 1.37 KB
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
/**
* Print information about the running program
* @author Mike Smith University of Brighton
* @version 1.0
*/
public class Debug
{
private static boolean debug = true;
/**
* Set true/false to print debugging information
* @param state Debugging true false
* @return The old state
*/
public static synchronized boolean set( boolean state )
{
boolean oldState = debug;
debug = state;
return oldState;
}
/**
* Display text for debugging purposes
* @param fmt The same as printf etc
* @param params The parameters to fmt
*/
public static void trace(String fmt, Object... params )
{
if ( debug )
{
synchronized( Debug.class )
{
System.out.printf( fmt, params );
System.out.println();
}
}
}
/**
* Display a fatal message if the assertion fails
* @param ok true if all is ok
* @param fmt The same as printf etc
* @param params The parameters to fmt
*/
public static void assertTrue( boolean ok, String fmt, Object... params )
{
if ( ! ok )
{
error( "Assert - " + fmt, params );
}
}
/**
* Display a fatal message
* @param fmt The same as printf etc
* @param params The parameters to fmt
*/
public static synchronized void error(String fmt, Object... params )
{
System.out.printf( "ERROR: " + fmt, params );
System.out.println();
}
}