Class Debug


  • public final class Debug
    extends Object
    A class to provide debug facilities in java.

    For assertTrue, to avoid evaluation of the boolean expression with debugging turned off on sun's java interpreter and with sun's javac use the following:

         Debug.assertTrue(Debug.enabled && anExpression, "error message");
     

    The short-cut semantics of '&&' will guarantee that anExpression will not be evaluated if enabled is set to false.

    Debug.print also won't print its argument if Debug.enabled is false. If the generation of the argument is already costly, you have to wrap it in an if-statement.

    Author:
    Andreas Gawecki
    • Method Detail

      • assertTrue

        public static void assertTrue​(boolean b,
                                      String s)
      • isSorted

        public static boolean isSorted​(int[] array)
        Method to use to assert that an array is sorted
        Parameters:
        array - the array
        Returns:
        true/false
      • isInArray

        public static boolean isInArray​(Object[] array,
                                        Object find)
        Method to use to assert that an array contains an object. Uses ==
        Parameters:
        array - the array
        find - the Object to find
        Returns:
        true/false
      • isInArray

        public static boolean isInArray​(String[] array,
                                        String find)
        Method to use to assert that an array contains a String. Uses equals.
        Parameters:
        array - the array
        find - the string to find
        Returns:
        if the array contains the string or not
      • isInArray

        public static boolean isInArray​(int[] array,
                                        int find)
        Method to use to assert that an array contains an int.
        Parameters:
        array - the array
        find - the int to find in the array
        Returns:
        if the array contains the int or not
      • println

        public static void println​(String x)
        Print a String, and then finish the line.
        Parameters:
        x - the string
      • println

        public static void println​(Object x)
        Print an Object, and then finish the line.
        Parameters:
        x - the object
      • printArray

        public static void printArray​(Object[] x)
        Print an Array.
        Parameters:
        x - the array
      • printArrayToString

        public static String printArrayToString​(Object[] x)
        Print an Object Array to a String.
        Parameters:
        x - the array
        Returns:
        the string
      • printArrayToString

        public static String printArrayToString​(int[] x)
        Print an int Array to a String.
        Parameters:
        x - the array
        Returns:
        the string
      • printArray

        public static void printArray​(int[] x)
        Print an Array.
        Parameters:
        x - the array