1package annotations.io;
2
3import java.io.PrintWriter;
4import java.util.logging.Level;
5
6/**
7 * @author dbro
8 */
9public class DebugWriter {
10  private PrintWriter out = new PrintWriter(System.out);
11  private Level level = Level.WARNING;
12
13  public DebugWriter or(final DebugWriter other) {
14    return new DebugWriter() {
15      @Override
16      public boolean isEnabled() {
17        return super.isEnabled() || other.isEnabled();
18      }
19    };
20  }
21
22  public static boolean anyEnabled(DebugWriter... debugs) {
23    for (DebugWriter debug : debugs) {
24      if (debug.isEnabled()) { return true; }
25    }
26    return false;
27  }
28
29  public boolean isEnabled() {
30    return level == Level.INFO;
31  }
32
33  public void setEnabled(boolean enabled) {
34    level = enabled ? Level.INFO : Level.WARNING;
35  }
36
37  public void debug(String format, Object... args) {
38    if (isEnabled()) {
39      out.print(String.format(format, args));
40      out.flush();
41    }
42  }
43}
44