Class | Tree | Index | Help
| AP® Computer Science Marine Biology Simulation
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## Class Debug

    java.lang.Object
      |
      +--Debug

public class Debug
extends java.lang.Object

AP® Computer Science Marine Biology Simulation:
The `Debug` class supports conditional printing of debugging messages.

The `turnOn` and `turnOff` methods cause the previous debugging state to be saved on a stack so that it can be restored later using the `restoreState` method.

For example, consider the following scenario. Method 1 turns on debugging and calls Method 2. Method 2, not knowing that debugging is already on, turns debugging on and calls Method 3. Method 3 turns debugging off. Before returning, Method 3 restores the previous state, which turns debugging back on (as set by Method 2). Before Method 2 returns, it also restores the state, which will leave debugging on (as set by Method 1). This is illustrated in the pseudo-code below.

          in Method 1:
              (A: in Method 1; we don't know debugging state)
              turn on debugging
              (debugging state is now on; Debug.println will print)
              call Method 2
                  (B: now in Method 2; debugging state is unchanged (on))
                  turn on debugging
                  (debugging state is on (still))
                  call Method 3
                      (C: now in Method 3; debugging state is unchanged (on))
                      turn off debugging
                      (debugging state is now off; Debug.println will not print)
                      restore state
                      (debugging state is restored to what it was at point C (on))
                      return to Method 2
                   (D: now in Method 2; debugging state is unchanged (still on))
                   restore state
                   (debugging state is still on because it was on at point B)
                   return to Method 1
               (E: now in Method 1; debugging state unchanged (still on))
               restore state
               (debugging state is whatever it was at point A (unknown))

Note that when Method 2 restores the debugging state, it does not go back to its most recent state, which would be off (as set by Method 3). State restoration is controlled by a stack, not by a toggle.

The `Debug` class is copyright© 2002 College Entrance Examination Board (www.collegeboard.com).

Version:
  1 July 2002

Constructor Summary
`Debug()`

Method Summary
`static boolean` | `isOff()` Checks whether debugging is off.
`static boolean` | `isOn()` Checks whether debugging is on.
`static void` | `print(java.lang.String message)` Prints debugging message without appending a newline character at the end.
`static void` | `println(java.lang.String message)` Prints debugging message, appending a newline character at the end.
`static void` | `restoreState()` Restores the previous debugging state.
`static void` | `turnOff()` Turns debugging off.
`static void` | `turnOn()` Turns debugging on.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Debug

    public Debug()

Method Detail

### isOn

    public static boolean isOn()

  Checks whether debugging is on. The `Debug.print` and `Debug.println`) methods use `isOn` to decide whether or not to print.

### isOff

    public static boolean isOff()

  Checks whether debugging is off.

### turnOn

    public static void turnOn()

  Turns debugging on.

### turnOff

    public static void turnOff()

  Turns debugging off.

### restoreState

    public static void restoreState()

  Restores the previous debugging state. If there is no previous state to restore, `restoreState` turns debugging off.

### print

    public static void print(java.lang.String message)

  Prints debugging message without appending a newline character at the end. If debugging is turned on, `message` is printed to `System.out` without a newline.
  Parameters:
    `message` - debugging message to print

### println

    public static void println(java.lang.String message)

  Prints debugging message, appending a newline character at the end. If debugging is turned on, `message` is printed to `System.out` followed by a newline.
  Parameters:
    `message` - debugging message to print

Class | Tree | Index | Help
| AP® Computer Science Marine Biology Simulation
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright© 2002 College Entrance Examination Board