Skip to content

Commit

Permalink
Convert cascading if-else to switch
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Sep 12, 2024
1 parent 203b89f commit 44233f5
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/examples/ListClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,39 @@ public static void main(final String[] argv) {
// Parse command line arguments.
for (final String arg : argv) {
if (arg.charAt(0) == '-') { // command line switch
if (arg.equals("-constants")) {
switch (arg) {
case "-constants":
constants = true;
} else if (arg.equals("-code")) {
break;
case "-code":
code = true;
} else if (arg.equals("-brief")) {
break;
case "-brief":
verbose = false;
} else if (arg.equals("-dependencies")) {
break;
case "-dependencies":
classdep = true;
} else if (arg.equals("-nocontents")) {
break;
case "-nocontents":
nocontents = true;
} else if (arg.equals("-recurse")) {
break;
case "-recurse":
recurse = true;
} else if (arg.equals("-exclude")) {
break;
case "-exclude":
exclude = true;
} else if (arg.equals("-help")) {
break;
case "-help":
System.out.println("Usage: java listclass [-constants] [-code] [-brief] " + "[-dependencies] [-nocontents] [-recurse] class... "
+ "[-exclude <list>]\n" + "-constants Print constants table (constant pool)\n" + "-code Dump byte code of methods\n"
+ "-brief Brief listing\n" + "-dependencies Show class dependencies\n"
+ "-nocontents Do not print field/method information\n" + "-recurse Recurse into dependent classes\n"
+ "-exclude <list> Do not list classes beginning with " + "strings in <list>");
System.exit(0);
} else {
break;
default:
System.err.println("Unknown switch " + arg + " ignored.");
break;
}
} else if (exclude) { // add file name to list
excludeName.add(arg);
Expand Down

0 comments on commit 44233f5

Please sign in to comment.