Class VerbosityUtil
- java.lang.Object
-
- de.bernd_michaely.common.cli.parser.VerbosityUtil
-
- Direct Known Subclasses:
CommandLineProcessor
public class VerbosityUtil extends Object
Utility class for handling the verbosity options of command line applications.
-
-
Constructor Summary
Constructors Constructor Description VerbosityUtil()
Constructor to initialize with no verbosity.VerbosityUtil(int verbosityLevel)
Constructor to initialize with given verbosity level.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
decreaseVerbosityLevel()
Decreases the verbosity level by one down to zero.PrintStream
getDefaultPrintStream()
Returns the default PrintStream.int
getVerbosityLevel()
Returns the current verbosity level.void
ifVerbose(Runnable runnable)
Performs the given action, if the verbosity level is at least one.void
ifVerboseFormat(PrintStream printStream, String msg, Object... args)
Format msg (without newline) to PrintStream.void
ifVerboseFormat(String msg, Object... args)
Format msg (without newline) to stdout.void
ifVerboseFormatln(PrintStream printStream, String msg, Object... args)
Format msg with newline to PrintStream.void
ifVerboseFormatln(String msg, Object... args)
Format msg with newline to stdout.void
ifVerbosePrint(String msg)
Print msg (without newline) to stdout.void
ifVerbosePrint(String msg, PrintStream printStream)
Print msg (without newline) to PrintStream.void
ifVerbosePrintln(String msg)
Print msg with newline to stdout.void
ifVerbosePrintln(String msg, PrintStream printStream)
Print msg with newline to PrintStream.void
ifVerbosePrintNewline()
Print single newline to stdout.void
ifVerbosePrintNewline(PrintStream printStream)
Print single newline to PrintStream.void
ifVerbosePrintNewlines(int num)
Print a number of newlines to stdout.void
ifVerbosePrintNewlines(int num, PrintStream printStream)
Print a number of newlines to PrintStream.int
increaseVerbosityLevel()
Increases the verbosity level by one up toInteger.MAX_VALUE
.boolean
isVerbose()
Returns true, if the verbosity level is at least one.void
setDefaultPrintStream(PrintStream defaultPrintStream)
Sets the default PrintStream.void
setVerbosityLevel(int verbosityLevel)
Sets the verbosity level the the given value.
-
-
-
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 toSystem.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 toInteger.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 printprintStream
- 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 printprintStream
- 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 printargs
- 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 tomsg
- the formatted message to printargs
- the args to format
-
ifVerboseFormatln
public void ifVerboseFormatln(String msg, Object... args)
Format msg with newline to stdout.- Parameters:
msg
- the formatted message to printargs
- 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 tomsg
- the formatted message to printargs
- 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 printprintStream
- the stream to print to
-
-