Class VerbosityUtil

  • Direct Known Subclasses:
    CommandLineProcessor

    public class VerbosityUtil
    extends Object
    Utility class for handling the verbosity options of command line applications.
    • Constructor Detail

      • VerbosityUtil

        public VerbosityUtil()
        Constructor to initialize with no verbosity.
      • VerbosityUtil

        public VerbosityUtil​(int verbosityLevel)
        Constructor to initialize with given verbosity level.
        Parameters:
        verbosityLevel - the given verbosity level
    • Method Detail

      • getDefaultPrintStream

        public PrintStream getDefaultPrintStream()
        Returns the default PrintStream.
        Returns:
        the default PrintStream
      • setDefaultPrintStream

        public void setDefaultPrintStream​(PrintStream defaultPrintStream)
        Sets the default PrintStream. The default PrintStream in turn defaults to System.out.
        Parameters:
        defaultPrintStream - the default PrintStream
      • getVerbosityLevel

        public int getVerbosityLevel()
        Returns the current verbosity level.
        Returns:
        the current verbosity level which is in the range of [0..Integer.MAX_VALUE]
      • setVerbosityLevel

        public void setVerbosityLevel​(int verbosityLevel)
        Sets the verbosity level the the given value. A negative value will be treated like zero.
        Parameters:
        verbosityLevel - the verbosity level to set
      • increaseVerbosityLevel

        public int increaseVerbosityLevel()
        Increases the verbosity level by one up to Integer.MAX_VALUE.
        Returns:
        the verbosity level after the change
      • decreaseVerbosityLevel

        public int decreaseVerbosityLevel()
        Decreases the verbosity level by one down to zero.
        Returns:
        the verbosity level after the change
      • isVerbose

        public boolean isVerbose()
        Returns true, if the verbosity level is at least one.
        Returns:
        true, if the verbosity level is at least one
      • ifVerbose

        public void ifVerbose​(Runnable runnable)
        Performs the given action, if the verbosity level is at least one.
        Parameters:
        runnable - the action to perform
      • ifVerbosePrint

        public void ifVerbosePrint​(String msg)
        Print msg (without newline) to stdout.
        Parameters:
        msg - the message to print
      • ifVerbosePrint

        public void ifVerbosePrint​(String msg,
                                   PrintStream printStream)
        Print msg (without newline) to PrintStream.
        Parameters:
        msg - the message to print
        printStream - the stream to print to
      • ifVerbosePrintln

        public void ifVerbosePrintln​(String msg)
        Print msg with newline to stdout.
        Parameters:
        msg - the message to print
      • ifVerbosePrintln

        public void ifVerbosePrintln​(String msg,
                                     PrintStream printStream)
        Print msg with newline to PrintStream.
        Parameters:
        msg - the message to print
        printStream - the stream to print to
      • ifVerboseFormat

        public void ifVerboseFormat​(String msg,
                                    Object... args)
        Format msg (without newline) to stdout.
        Parameters:
        msg - the formatted message to print
        args - the args to format
      • ifVerboseFormat

        public void ifVerboseFormat​(PrintStream printStream,
                                    String msg,
                                    Object... args)
        Format msg (without newline) to PrintStream.
        Parameters:
        printStream - the stream to print to
        msg - the formatted message to print
        args - the args to format
      • ifVerboseFormatln

        public void ifVerboseFormatln​(String msg,
                                      Object... args)
        Format msg with newline to stdout.
        Parameters:
        msg - the formatted message to print
        args - the args to format
      • ifVerboseFormatln

        public void ifVerboseFormatln​(PrintStream printStream,
                                      String msg,
                                      Object... args)
        Format msg with newline to PrintStream.
        Parameters:
        printStream - the stream to print to
        msg - the formatted message to print
        args - the args to format
      • ifVerbosePrintNewline

        public void ifVerbosePrintNewline()
        Print single newline to stdout.
      • ifVerbosePrintNewline

        public void ifVerbosePrintNewline​(PrintStream printStream)
        Print single newline to PrintStream.
        Parameters:
        printStream - the stream to print to
      • ifVerbosePrintNewlines

        public void ifVerbosePrintNewlines​(int num)
        Print a number of newlines to stdout.
        Parameters:
        num - the number of newlines to print
      • ifVerbosePrintNewlines

        public void ifVerbosePrintNewlines​(int num,
                                           PrintStream printStream)
        Print a number of newlines to PrintStream.
        Parameters:
        num - the number of newlines to print
        printStream - the stream to print to