org.fenfire.util
Class Dbg

java.lang.Object
  |
  +--org.fenfire.util.Dbg

public final class Dbg
extends java.lang.Object

Turning on debugging according to gzz conventions. The GZigZag convention for debuggable classes is that every class must have a public static member dbg, e.g. as in

 class Foo {
	static public boolean dbg = false;
      ...
	private final void p(String s) { if(dbg) System.out.println(s); }
      ...
      ...
      void method() {
         p("Here");
         ...
         if(dbg)
             object-<printDebugInfo();
         ...
      }
 }
 
This member can be turned on from outside.

Caveats

Efficiency
Some Java versions, such as Kaffe 1.0.6, are not smart enough to optimize code like
 p("AGG "+object+" "+object2+" "+number);
			
so that the string is not formed if dbg is false. This is very unfortunate. If code like above is inside tight loops, a profiler will show that your program is spending a good amount of its time in StringBuffer code, making strings that will never be used for anything. Therefore, the above statements, especially in tight loops, should be changed to
 if(dbg) p("AGG "+object+" "+object2+" "+number);
			
Class garbage collection
Some (most?) Java implementations garbage-collect classes. This means that setting the static dbg value may not last if the class is garbage-collected and then reloaded. Because of this, Dbg keeps inside it a list of the classes for which debugging has been turned on. Therefore, you should keep the Dbg object somewhere where it will not be garbage collected.


Field Summary
static java.lang.String rcsid
           
 
Constructor Summary
Dbg()
           
 
Method Summary
 void debugClass(java.lang.String name, boolean dbg)
          Turn on debugging for a class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rcsid

public static final java.lang.String rcsid
See Also:
Constant Field Values
Constructor Detail

Dbg

public Dbg()
Method Detail

debugClass

public void debugClass(java.lang.String name,
                       boolean dbg)
Turn on debugging for a class.

Parameters:
name - The name of the class (without the gzz. prefix.)
dbg - Whether to turn debugging on or off.