## org.mortbay.util
Class Code

    java.lang.Object
      |
      +--org.mortbay.util.Code

public class Code
extends java.lang.Object

Coding Standards support. Support for defensive programming Coding defensively as follows:

     {
        ...
        Code.assertTrue(booleanExpression(),"Assert that expression evaluates true");
        ...
        Code.assertEquals(objectA,objectB,"Assert equality");
        Code.assertEquals(1,2,"Assert equality");
        ...
        Code.debug("Debug message");
        ...
        Code.debug("Debug message",exception,object);
        ...
        Code.warning("warning message");
        ...
        Code.warning("warning message",exception);
        ...
        Code.notImplemented();
        Code.fail("fatal error");
        ...
     }

The debug output can be controlled with java properties:

- DEBUG - If set, debug output is enabled
- DEBUG_PATTERNS - If set to a comma separated list of strings, Then debug output is only produced from those classes whose fully qualified class name contains one of the strings as a substring.
- DEBUG_OPTIONS - A string of option character. 'W' - suppress warnings unless debug is on, 'S' suppress stack frame dumps
- DEBUG_VERBOSE - Set to an integer verbosity level for use in controlling debug verbosity (see verbose(int))

  #### Usage

       java [-DDEBUG [-DDEBUG_PATTERNS="MyClass,my.package"] \\
                     [-DDEBUG_OPTIONS=[S][W]] \\
                     [-DDEBUG_VERBOSE=n] ] \\
            my.package.main

  Version:
    $Id: Code.java,v 1.20 2003/06/27 19:23:41 hlavac Exp $
  Author:
    Greg Wilkins

  Nested Class Summary
  `static class` `Code.LogMsg` Log Message Object passed to the Log by Code.

  Method Summary
  `static void` `assertContains(java.lang.String string, java.lang.String sub, java.lang.String m)` Check assertion that a string is a substring of another.
  `static void` `assertEquals(char o1, char o2, java.lang.String m)` Check assertion that o1==o2.
  `static void` `assertEquals(double o1, double o2, java.lang.String m)` Check assertion that o1==o2.
  `static void` `assertEquals(long o1, long o2, java.lang.String m)` Check assertion that o1==o2.
  `static void` `assertEquals(java.lang.Object o1, java.lang.Object o2, java.lang.String m)` Check assertion that o1==o2.
  `static void` `assertTrue(boolean b, java.lang.String m)` Check assertion that a boolean is true.
  `static boolean` `debug()` Get debug status for the current stack frame.
  `static void` `debug(int depth, java.lang.Object o)` Debug with frame depth.
  `static void` `debug(java.lang.Object o)` As debug(String) Do not rely on side-effects
  `static void` `debug(java.lang.Object o1, long l)` As debug(String) Do not rely on side-effects
  `static void` `debug(java.lang.Object o1, long l1, java.lang.Object o2, long l2)` As debug(String) Do not rely on side-effects
  `static void` `debug(java.lang.Object o1, java.lang.Object o2)` As debug(String) Do not rely on side-effects
  `static void` `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)` As debug(String) Do not rely on side-effects
  `static void` `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4)` As debug(String) Do not rely on side-effects
  `static void` `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5)` As debug(String) Do not rely on side-effects
  `static void` `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5, java.lang.Object o6)` As debug(String) Do not rely on side-effects
  `static void` `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5, java.lang.Object o6, java.lang.Object o7)` As debug(String) Do not rely on side-effects
  `static void` `debug(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5, java.lang.Object o6, java.lang.Object o7, java.lang.Object o8)` As debug(String) Do not rely on side-effects
  `static void` `debug(java.lang.String m)` Programming debugging output sent to the Log.
  `static void` `debug(java.lang.String m, java.lang.Throwable ex)` As debug(String) Do not rely on side-effects
  `static void` `debug(java.lang.Throwable ex)` As debug(String) Dont rely on side-effects
  `static void` `fail(java.lang.String m)` Programmer initiated fatal CodeException.
  `static void` `fail(java.lang.String m, java.lang.Throwable ex)` Programmer initiated fatal error.
  `static void` `fail(java.lang.Throwable ex)` Programmer initiated fatal error.
  `static boolean` `getDebug()` Get the debug status.
  `static java.lang.String` `getDebugPatterns()` Get the debug patterns.
  `static boolean` `getSuppressStack()` Get the stack suppression status.
  `static boolean` `getSuppressWarnings()` Get the warnings suppression status.
  `static int` `getVerbose()` Get the verbosity level.
  `static void` `ignore(java.lang.Throwable ex)` Ignore an exception.
  `static Code` `instance()`
  `static void` `notImplemented()` Standard fatal error for a method not yet implemented.
  `static void` `setDebug(boolean debug)` Set if debugging is on or off.
  `static void` `setDebugPatterns(java.lang.String patterns)` Set debug patterns.
  `static void` `setSuppressStack(boolean stack)` Suppress stack trace.
  `static void` `setSuppressWarnings(boolean warnings)` Set warning suppression.
  `static void` `setVerbose(int verbose)` Set verbosity level.
  `static boolean` `verbose()` Get verbosity level.
  `static boolean` `verbose(int v)` Get verbosity level.
  `static void` `warning(java.lang.String m)` Programmer initiated warning, intended to be viewed by technical not operational staff.
  `static void` `warning(java.lang.String m, java.lang.Throwable ex)` Programmer initiated warning, intended to be viewed by technical not operational staff.
  `static void` `warning(java.lang.Throwable ex)` Programmer initiated warning, intended to be viewed by technical not operational staff.

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

  Method Detail

  ### instance

      public static Code instance()

  ### setDebug

      public static void setDebug(boolean debug)

    Set if debugging is on or off.

    Parameters:
      `debug` -

  ### getDebug

      public static boolean getDebug()

    Get the debug status.

    Returns:
      the debug status

  ### setSuppressStack

      public static void setSuppressStack(boolean stack)

    Suppress stack trace.

    Parameters:
      `stack` - if true stacks are not produced

  ### getSuppressStack

      public static boolean getSuppressStack()

    Get the stack suppression status.

    Returns:
      the stack suppression status

  ### setSuppressWarnings

      public static void setSuppressWarnings(boolean warnings)

    Set warning suppression.

    Parameters:
      `warnings` - Warnings suppress if this is true and debug is false

  ### getSuppressWarnings

      public static boolean getSuppressWarnings()

    Get the warnings suppression status.

    Returns:
      the warnings suppression status

  ### setVerbose

      public static void setVerbose(int verbose)

    Set verbosity level.

    Parameters:
      `verbose` -

  ### getVerbose

      public static int getVerbose()

    Get the verbosity level.

    Returns:
      the verbosity level

  ### setDebugPatterns

      public static void setDebugPatterns(java.lang.String patterns)

    Set debug patterns.

    Parameters:
      `patterns` - comma separated string of patterns

  ### getDebugPatterns

      public static java.lang.String getDebugPatterns()

    Get the debug patterns.

    Returns:
      Coma separated list of debug patterns

  ### assertTrue

      public static void assertTrue(boolean b,
                                    java.lang.String m)

    Check assertion that a boolean is true. Logs and throws CodeException if the assertion fails.

    Parameters:
      `b` - The boolean to assert is true
      `m` - Message to log if assertion fails
    Throws:
      `CodeException` - Thrown if assertion fails

  ### assertEquals

      public static void assertEquals(java.lang.Object o1,
                                      java.lang.Object o2,
                                      java.lang.String m)

    Check assertion that o1==o2. Logs and throws CodeException if the assertion fails.

    Parameters:
      `o1` - The first object to check
      `o2` - The first object to check
      `m` - Message to log if assertion fails
    Throws:
      `CodeException` - Thrown if assertion fails

  ### assertEquals

      public static void assertEquals(long o1,
                                      long o2,
                                      java.lang.String m)

    Check assertion that o1==o2. Logs and throws CodeException if the assertion fails.

    Parameters:
      `o1` - The first long to check
      `o2` - The first long to check
      `m` - Message to log if assertion fails
    Throws:
      `CodeException` - Thrown if assertion fails

  ### assertEquals

      public static void assertEquals(double o1,
                                      double o2,
                                      java.lang.String m)

    Check assertion that o1==o2. Logs and throws CodeException if the assertion fails.

    Parameters:
      `o1` - The first double to check
      `o2` - The first double to check
      `m` - Message to log if assertion fails
    Throws:
      `CodeException` - Thrown if assertion fails

  ### assertEquals

      public static void assertEquals(char o1,
                                      char o2,
                                      java.lang.String m)

    Check assertion that o1==o2. Logs and throws CodeException if the assertion fails.

    Parameters:
      `o1` - The first char to check
      `o2` - The first char to check
      `m` - Message to log if assertion fails
    Throws:
      `CodeException` - Thrown if assertion fails

  ### assertContains

      public static void assertContains(java.lang.String string,
                                        java.lang.String sub,
                                        java.lang.String m)

    Check assertion that a string is a substring of another. Logs and throws CodeException if the assertion fails.

    Parameters:
      `string` - The string
      `sub` - The sub string
      `m` - Message to log if assertion fails
    Throws:
      `CodeException` - Thrown if assertion fails

  ### warning

      public static void warning(java.lang.String m)

    Programmer initiated warning, intended to be viewed by technical not operational staff.

    Parameters:
      `m` - The message body of the warning

  ### warning

      public static void warning(java.lang.String m,
                                 java.lang.Throwable ex)

    Programmer initiated warning, intended to be viewed by technical not operational staff.

    Parameters:
      `m` - The message body of the warning
      `ex` - A Throwable object

  ### warning

      public static void warning(java.lang.Throwable ex)

    Programmer initiated warning, intended to be viewed by technical not operational staff.

    Parameters:
      `ex` - A Throwable object

  ### fail

      public static void fail(java.lang.String m)

    Programmer initiated fatal CodeException.

    Parameters:
      `m` - The message body to log with the fatal error
    Throws:
      `CodeException` - thrown to cause fatal error

  ### fail

      public static void fail(java.lang.String m,
                              java.lang.Throwable ex)

    Programmer initiated fatal error.

    Parameters:
      `m` - The message body to log with the fatal error
      `ex` - The Throwable to print the full stack trace of
    Throws:
      `CodeException` - thrown to cause fatal error

  ### fail

      public static void fail(java.lang.Throwable ex)

    Programmer initiated fatal error.

    Parameters:
      `ex` - The Throwable to print the full stack trace of
    Throws:
      `CodeException` - thrown to cause fatal error

  ### notImplemented

      public static void notImplemented()

    Standard fatal error for a method not yet implemented.

  ### verbose

      public static boolean verbose()

    Get verbosity level.

    Returns:
      true if any level of verbosity is set.

  ### verbose

      public static boolean verbose(int v)

    Get verbosity level.

    Parameters:
      `v` - verbosity level to check against
    Returns:
      true if current level of verbosity greater than or equal to v

  ### debug

      public static boolean debug()

    Get debug status for the current stack frame.

    Returns:
      true if debug is on for this stack frame

  ### debug

      public static void debug(java.lang.String m)

    Programming debugging output sent to the Log. For debug output to be generated, the property DEBUG must be passed to the java VM. If the property DEBUG_PATTERN is set, it is used as a regular expression on the method, file and thread names to filter debug generation. Do not rely on side-effects

    Parameters:
      `m` - The debug message to log.

  ### debug

      public static void debug(java.lang.String m,
                               java.lang.Throwable ex)

    As debug(String) Do not rely on side-effects

    Parameters:
      `m` - The debug message to log.
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(java.lang.Throwable ex)

    As debug(String) Dont rely on side-effects

    Parameters:
      `ex` - The Throwable to print the full stack trace of

  ### debug

      public static void debug(int depth,
                               java.lang.Object o)

    Debug with frame depth.

    Parameters:
      `depth` - Depth of debug frame, 1=caller, 2=callers caller...
      `o` - Object

  ### debug

      public static void debug(java.lang.Object o)

    As debug(String) Do not rely on side-effects

    Parameters:
      `o` - The Object to pass to the debug Log.

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2)

    As debug(String) Do not rely on side-effects

    Parameters:
      `o1` - An Object to pass to the debug Log.
      `o2` - Another Object to pass to the debug Log.

  ### debug

      public static void debug(java.lang.Object o1,
                               long l)

    As debug(String) Do not rely on side-effects

    Parameters:
      `o1` - An Object to pass to the debug Log.
      `l` - a long to wrap as a Long and pass to Log.

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3)

    As debug(String) Do not rely on side-effects

    Parameters:
      `o1` - An Object to pass to the debug Log.
      `o2` - Another Object to pass to the debug Log.
      `o3` - Another Object to pass to the debug Log.

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3,
                               java.lang.Object o4)

    As debug(String) Do not rely on side-effects

    Parameters:
      `o1` - An Object to pass to the debug Log.
      `o2` - Another Object to pass to the debug Log.
      `o3` - Another Object to pass to the debug Log.
      `o4` - Another Object to pass to the debug Log.

  ### debug

      public static void debug(java.lang.Object o1,
                               long l1,
                               java.lang.Object o2,
                               long l2)

    As debug(String) Do not rely on side-effects

    Parameters:
      `o1` - An Object to pass to the debug Log.
      `l1` - a long to wrap as a Long and pass to Log.
      `o2` - Another Object to pass to the debug Log.
      `l2` - Another long to wrap as a Long and pass to Log.

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3,
                               java.lang.Object o4,
                               java.lang.Object o5)

    As debug(String) Do not rely on side-effects

    Parameters:
      `o1` - An Object to pass to the debug Log.
      `o2` - Another Object to pass to the debug Log.
      `o3` - Another Object to pass to the debug Log.
      `o4` - Another Object to pass to the debug Log.
      `o5` - Another Object to pass to the debug Log.

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3,
                               java.lang.Object o4,
                               java.lang.Object o5,
                               java.lang.Object o6)

    As debug(String) Do not rely on side-effects

    Parameters:
      `o1` - An Object to pass to the debug Log.
      `o2` - Another Object to pass to the debug Log.
      `o3` - Another Object to pass to the debug Log.
      `o4` - Another Object to pass to the debug Log.
      `o5` - Another Object to pass to the debug Log.
      `o6` - Another Object to pass to the debug Log.

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3,
                               java.lang.Object o4,
                               java.lang.Object o5,
                               java.lang.Object o6,
                               java.lang.Object o7)

    As debug(String) Do not rely on side-effects

    Parameters:
      `o1` - An Object to pass to the debug Log.
      `o2` - Another Object to pass to the debug Log.
      `o3` - Another Object to pass to the debug Log.
      `o4` - Another Object to pass to the debug Log.
      `o5` - Another Object to pass to the debug Log.
      `o6` - Another Object to pass to the debug Log.
      `o7` - Another Object to pass to the debug Log.

  ### debug

      public static void debug(java.lang.Object o1,
                               java.lang.Object o2,
                               java.lang.Object o3,
                               java.lang.Object o4,
                               java.lang.Object o5,
                               java.lang.Object o6,
                               java.lang.Object o7,
                               java.lang.Object o8)

    As debug(String) Do not rely on side-effects

    Parameters:
      `o1` - An Object to pass to the debug Log.
      `o2` - Another Object to pass to the debug Log.
      `o3` - Another Object to pass to the debug Log.
      `o4` - Another Object to pass to the debug Log.
      `o5` - Another Object to pass to the debug Log.
      `o6` - Another Object to pass to the debug Log.
      `o7` - Another Object to pass to the debug Log.
      `o8` - Another Object to pass to the debug Log.

  ### ignore

      public static void ignore(java.lang.Throwable ex)

    Ignore an exception.

    Parameters:
      `ex` - The Throwable to print the full stack trace of

  Copyright © 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.