Skip to content

Commit 98d06d3

Browse files
committed
No need to nest in else.
1 parent 5f0dc62 commit 98d06d3

5 files changed

Lines changed: 24 additions & 35 deletions

File tree

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ private boolean isLongOption(final String token)
383383
// long or partial long options (--L, -L, --L=V, -L=V, --l, --l=V)
384384
return true;
385385
}
386-
else if (getLongPrefix(token) != null && !token.startsWith("--"))
386+
if (getLongPrefix(token) != null && !token.startsWith("--"))
387387
{
388388
// -LV
389389
return true;
@@ -759,20 +759,16 @@ protected void handleConcatenatedOptions(final String token) throws ParseExcepti
759759
{
760760
final String ch = String.valueOf(token.charAt(i));
761761

762-
if (options.hasOption(ch))
763-
{
764-
handleOption(options.getOption(ch));
765-
766-
if (currentOption != null && token.length() != i + 1)
767-
{
768-
// add the trail as an argument of the option
769-
currentOption.addValueForProcessing(token.substring(i + 1));
770-
break;
771-
}
762+
if (!options.hasOption(ch)) {
763+
handleUnknownToken(stopAtNonOption && i > 1 ? token.substring(i) : token);
764+
break;
772765
}
773-
else
766+
handleOption(options.getOption(ch));
767+
768+
if (currentOption != null && token.length() != i + 1)
774769
{
775-
handleUnknownToken(stopAtNonOption && i > 1 ? token.substring(i) : token);
770+
// add the trail as an argument of the option
771+
currentOption.addValueForProcessing(token.substring(i + 1));
776772
break;
777773
}
778774
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,10 @@ public void setSelected(final Option option) throws AlreadySelectedException
9393
// if no option has already been selected or the
9494
// same option is being reselected then set the
9595
// selected member variable
96-
if (selected == null || selected.equals(option.getKey()))
97-
{
98-
selected = option.getKey();
99-
}
100-
else
101-
{
96+
if ((selected != null) && !selected.equals(option.getKey())) {
10297
throw new AlreadySelectedException(this, option);
10398
}
99+
selected = option.getKey();
104100
}
105101

106102
/**

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,42 +67,39 @@ public static <T> T createValue(final String str, final Class<T> clazz) throws P
6767
{
6868
return (T) str;
6969
}
70-
else if (PatternOptionBuilder.OBJECT_VALUE == clazz)
70+
if (PatternOptionBuilder.OBJECT_VALUE == clazz)
7171
{
7272
return (T) createObject(str);
7373
}
74-
else if (PatternOptionBuilder.NUMBER_VALUE == clazz)
74+
if (PatternOptionBuilder.NUMBER_VALUE == clazz)
7575
{
7676
return (T) createNumber(str);
7777
}
78-
else if (PatternOptionBuilder.DATE_VALUE == clazz)
78+
if (PatternOptionBuilder.DATE_VALUE == clazz)
7979
{
8080
return (T) createDate(str);
8181
}
82-
else if (PatternOptionBuilder.CLASS_VALUE == clazz)
82+
if (PatternOptionBuilder.CLASS_VALUE == clazz)
8383
{
8484
return (T) createClass(str);
8585
}
86-
else if (PatternOptionBuilder.FILE_VALUE == clazz)
86+
if (PatternOptionBuilder.FILE_VALUE == clazz)
8787
{
8888
return (T) createFile(str);
8989
}
90-
else if (PatternOptionBuilder.EXISTING_FILE_VALUE == clazz)
90+
if (PatternOptionBuilder.EXISTING_FILE_VALUE == clazz)
9191
{
9292
return (T) openFile(str);
9393
}
94-
else if (PatternOptionBuilder.FILES_VALUE == clazz)
94+
if (PatternOptionBuilder.FILES_VALUE == clazz)
9595
{
9696
return (T) createFiles(str);
9797
}
98-
else if (PatternOptionBuilder.URL_VALUE == clazz)
98+
if (PatternOptionBuilder.URL_VALUE == clazz)
9999
{
100100
return (T) createURL(str);
101101
}
102-
else
103-
{
104-
throw new ParseException("Unable to handle the class: " + clazz);
105-
}
102+
throw new ParseException("Unable to handle the class: " + clazz);
106103
}
107104

108105
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static String stripLeadingHyphens(final String str)
4040
{
4141
return str.substring(2);
4242
}
43-
else if (str.startsWith("-"))
43+
if (str.startsWith("-"))
4444
{
4545
return str.substring(1);
4646
}

src/test/java/org/apache/commons/cli/ParserTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,11 +930,11 @@ public void testUnlimitedArgs() throws Exception
930930
private CommandLine parse(final CommandLineParser parser, final Options opts, final String[] args, final Properties properties) throws ParseException {
931931
if (parser instanceof Parser) {
932932
return ((Parser) parser).parse(opts, args, properties);
933-
} else if (parser instanceof DefaultParser) {
933+
}
934+
if (parser instanceof DefaultParser) {
934935
return ((DefaultParser) parser).parse(opts, args, properties);
935-
} else {
936-
throw new UnsupportedOperationException("Default options not supported by this parser");
937936
}
937+
throw new UnsupportedOperationException("Default options not supported by this parser");
938938
}
939939

940940
@Test

0 commit comments

Comments
 (0)