Skip to content

Commit 7199a70

Browse files
committed
Use forEachRemaining
- Reduce vertical whitespace - Better private method name
1 parent e852acf commit 7199a70

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,10 @@ public String toString() {
162162
buff.append(OptionFormatter.DEFAULT_LONG_OPT_PREFIX);
163163
buff.append(option.getLongOpt());
164164
}
165-
166165
if (option.getDescription() != null) {
167166
buff.append(Char.SP);
168167
buff.append(option.getDescription());
169168
}
170-
171169
if (iter.hasNext()) {
172170
buff.append(", ");
173171
}

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ public PosixParser() {
5252
// empty
5353
}
5454

55+
/**
56+
* Adds the remaining tokens to the processed tokens list.
57+
*
58+
* @param iter An iterator over the remaining tokens
59+
*/
60+
private void addRemaining(final Iterator<String> iter) {
61+
if (eatTheRest) {
62+
iter.forEachRemaining(tokens::add);
63+
}
64+
}
65+
5566
/**
5667
* Breaks {@code token} into its constituent parts using the following algorithm.
5768
*
@@ -171,24 +182,11 @@ protected String[] flatten(final Options options, final String[] arguments, fina
171182
processNonOptionToken(token, stopAtNonOption);
172183
}
173184
}
174-
gobble(iter);
185+
addRemaining(iter);
175186
}
176187
return tokens.toArray(Util.EMPTY_STRING_ARRAY);
177188
}
178189

179-
/**
180-
* Adds the remaining tokens to the processed tokens list.
181-
*
182-
* @param iter An iterator over the remaining tokens
183-
*/
184-
private void gobble(final Iterator<String> iter) {
185-
if (eatTheRest) {
186-
while (iter.hasNext()) {
187-
tokens.add(iter.next());
188-
}
189-
}
190-
}
191-
192190
/**
193191
* Resets the members to their original state i.e. remove all of {@code tokens} entries and set
194192
* {@code eatTheRest} to false.

src/main/java/org/apache/commons/cli/help/AbstractHelpFormatter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ public String toSyntaxOptions(final OptionGroup group) {
472472
formatter = optionFormatBuilder.build(iter.next());
473473
// whether the option is required or not is handled at group level
474474
buff.append(formatter.toSyntaxOption(true));
475-
476475
if (iter.hasNext()) {
477476
buff.append(optionGroupSeparator);
478477
}

0 commit comments

Comments
 (0)