Skip to content

Commit ce5ebdf

Browse files
committed
[CLI-240] Small cleanup of Options class, thanks to Beluga Behr.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@1544802 13f79535-47bb-0310-9956-ffa450edef68
1 parent f9bc181 commit ce5ebdf

3 files changed

Lines changed: 11 additions & 17 deletions

File tree

RELEASE-NOTES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ BUG FIXES:
7272

7373
CHANGES:
7474

75+
* Small cleanup of Option class. Thanks to Beluga Behr. (CLI-240)
76+
7577
* Options.getRequiredOptions() now returns an unmodifiable list. (CLI-230)
7678

7779
* Clarify javadoc for CommandLine.getOptionValue() that the first specified

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<body>
2424

2525
<release version="1.3" date="in SVN" description="This is a maintenance release containing bug fixes.">
26+
<action type="update" dev="tn" issue="CLI-240" due-to="Beluga Behr">
27+
Small cleanup of Option class.
28+
</action>
2629
<action type="update" dev="tn" issue="CLI-231" due-to="Duncan Jones">
2730
Removed DoubleCheckedLocking test from checkstyle configuration.
2831
</action>

src/main/java/org/apache/commons/cli/Option.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,7 @@ public int getId()
177177
String getKey()
178178
{
179179
// if 'opt' is null, then it is a 'long' option
180-
if (opt == null)
181-
{
182-
return longOpt;
183-
}
184-
185-
return opt;
180+
return (opt == null) ? longOpt : opt;
186181
}
187182

188183
/**
@@ -435,14 +430,11 @@ public int getArgs()
435430
*/
436431
void addValueForProcessing(String value)
437432
{
438-
switch (numberOfArgs)
433+
if (numberOfArgs == UNINITIALIZED)
439434
{
440-
case UNINITIALIZED:
441-
throw new RuntimeException("NO_ARGS_ALLOWED");
442-
443-
default:
444-
processValue(value);
435+
throw new RuntimeException("NO_ARGS_ALLOWED");
445436
}
437+
processValue(value);
446438
}
447439

448440
/**
@@ -743,12 +735,9 @@ boolean requiresArg()
743735
}
744736
if (numberOfArgs == UNLIMITED_VALUES)
745737
{
746-
return values.size() < 1;
747-
}
748-
else
749-
{
750-
return acceptsArg();
738+
return values.isEmpty();
751739
}
740+
return acceptsArg();
752741
}
753742

754743
/**

0 commit comments

Comments
 (0)