Package Torello.Java
Enum Verbosity
- java.lang.Object
-
- java.lang.Enum<Verbosity>
-
- Torello.Java.Verbosity
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<Verbosity>
public enum Verbosity extends java.lang.Enum<Verbosity>
A Java'enum'
that is used in several locations in theJava-HTML JAR
Library to allow an end-user to request the quantity of text being produced by a tool or application. TheVerbose
flag / constant is designed to request the maximum amount of information when running a tool, while theSilent
constant may be used to ask that no textual output be sent to Standard-Output
Primarily for convenience and ease-of-use, each of the four constants in thisenum
are assigned an integer depicting the verbosity. When deciding whether or not to print a message to the user using thisenum
, using thelevel
integer is usually a more exedient coding-solution.
The following example should help elucidate using thelevel
field. Note that in this particular example, the settings forQuiet
and forSilent
are simply not being used. In this example, keep in mind that the programmer may simply include a message for theQuiet
setting someplace else in the code, entirely!
Example:
// This is an extremely verbose way of coding! switch (verbosity) { case Silent: case Quiet: break; case Normal: case Verbose: System.out.println("Starting New Program Section"); } // From a programming-analysis perspective alone, this is a lot more succint if (verbosity.level >= 2) System.out.println("Starting New Program Section");
Hi-Lited Source-Code:- View Here: Torello/Java/Verbosity.java
- Open New Browser-Tab: Torello/Java/Verbosity.java
File Size: 5,015 Bytes Line Count: 121 '\n' Characters Found
-
-
Field Summary
Fields Modifier and Type Field int
level
-
Method Summary
Convert String to Enum Constant Modifier and Type Method static Verbosity
valueOf(String name)
List all Enum Constants Modifier and Type Method static Verbosity[]
values()
More Methods Modifier and Type Method static Verbosity
get(int verbosityLevel)
-
-
-
Enum Constant Detail
-
Silent
public static final Verbosity Silent
Indicates a user-request that an application or program should not produce any output, other than error-output. In theJava-HTML JAR
Library, error output is rarely abbreviated or eliminated.
This constant is assigned "Level 0", and thelevel
constant-field will always be zero.
-
Quiet
public static final Verbosity Quiet
Indicates a user-request for an application or program to run producing the minimum amount of text-output possible. Error output may (or may not) be shunted, as per the capricious whims of the software guys.
This constant is assigned "Level 1", and thelevel
constant-field will always be one.
-
Normal
-
Verbose
public static final Verbosity Verbose
If a programmer can produce additional information about the state of a program as it runs, then the'Verbose'
constant / flag may be used to indicate a user-request as such.
This constant is assigned "Level 3", and thelevel
constant-field will always be three.
-
-
Field Detail
-
level
public final int level
There are quite a number of situations where an integer is easier for doing the comparisons an actual instance of'Verbosity'
. Each of the four constants of thisenum
have their own, ordered,'level'
setting (which is a number between'0'
and'3'
).
-
-
Method Detail
-
values
public static Verbosity[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (Verbosity c : Verbosity.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Verbosity valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
get
public static Verbosity get(int verbosityLevel)
Retrieves the Enum-Constant associated with the integer parameter'verbosityLevel'
.- Parameters:
verbosityLevel
- This must be a value between'0'
and'3'
, or an IllegalArgumentException will throw.
This is used to indicate which of the four constants are to be returned by this method.Constant Integer Level Silent
0
Quiet
1
Normal
2
Verbose
3
- Returns:
- The Enum-Constant associated with the input
'verbosityLevel'
- Throws:
java.lang.IllegalArgumentException
- If an integer-value other than the above four possible values is provided as input.- Code:
- Exact Method Body:
if ((verbosityLevel < 0) || (verbosityLevel > 3)) throw new IllegalArgumentException ("verbosityLevel=" + verbosityLevel + ", but this value must be between 0 and 3."); switch (verbosityLevel) { case 0: return Silent; case 1: return Quiet; case 2: return Normal; case 3: return Verbose; default: throw new UnreachableError(); }
-
-