Skip to content

Commit 357a8b0

Browse files
committed
Add final modifier to local variables.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@1797673 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9a048d0 commit 357a8b0

37 files changed

Lines changed: 724 additions & 723 deletions

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public Collection<String> getMatchingOptions()
6666
*/
6767
private static String createMessage(String option, Collection<String> matchingOptions)
6868
{
69-
StringBuilder buf = new StringBuilder("Ambiguous option: '");
69+
final StringBuilder buf = new StringBuilder("Ambiguous option: '");
7070
buf.append(option);
7171
buf.append("' (could be: ");
7272

73-
Iterator<String> it = matchingOptions.iterator();
73+
final Iterator<String> it = matchingOptions.iterator();
7474
while (it.hasNext())
7575
{
7676
buf.append("'");

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public Object getOptionObject(String opt)
104104
{
105105
return getParsedOptionValue(opt);
106106
}
107-
catch (ParseException pe)
107+
catch (final ParseException pe)
108108
{
109109
System.err.println("Exception found converting " + opt + " to desired type: " + pe.getMessage());
110110
return null;
@@ -126,7 +126,7 @@ public Object getParsedOptionValue(Option option) throws ParseException
126126
{
127127
return null;
128128
}
129-
String res = getOptionValue(option);
129+
final String res = getOptionValue(option);
130130
if (res == null)
131131
{
132132
return null;
@@ -188,7 +188,7 @@ public String getOptionValue(Option option)
188188
{
189189
return null;
190190
}
191-
String[] values = getOptionValues(option);
191+
final String[] values = getOptionValues(option);
192192
return (values == null) ? null : values[0];
193193
}
194194

@@ -226,9 +226,9 @@ public String getOptionValue(char opt)
226226
*/
227227
public String[] getOptionValues(Option option)
228228
{
229-
List<String> values = new ArrayList<String>();
229+
final List<String> values = new ArrayList<String>();
230230

231-
for (Option processedOption : options)
231+
for (final Option processedOption : options)
232232
{
233233
if (processedOption.equals(option))
234234
{
@@ -260,7 +260,7 @@ public String[] getOptionValues(String opt)
260260
private Option resolveOption(String opt)
261261
{
262262
opt = Util.stripLeadingHyphens(opt);
263-
for (Option option : options)
263+
for (final Option option : options)
264264
{
265265
if (opt.equals(option.getOpt()))
266266
{
@@ -300,7 +300,7 @@ public String[] getOptionValues(char opt)
300300
*/
301301
public String getOptionValue(Option option, String defaultValue)
302302
{
303-
String answer = getOptionValue(option);
303+
final String answer = getOptionValue(option);
304304
return (answer != null) ? answer : defaultValue;
305305
}
306306

@@ -347,13 +347,13 @@ public String getOptionValue(char opt, String defaultValue)
347347
*/
348348
public Properties getOptionProperties(Option option)
349349
{
350-
Properties props = new Properties();
350+
final Properties props = new Properties();
351351

352-
for (Option processedOption : options)
352+
for (final Option processedOption : options)
353353
{
354354
if (processedOption.equals(option))
355355
{
356-
List<String> values = processedOption.getValuesList();
356+
final List<String> values = processedOption.getValuesList();
357357
if (values.size() >= 2)
358358
{
359359
// use the first 2 arguments as the key/value pair
@@ -385,13 +385,13 @@ else if (values.size() == 1)
385385
*/
386386
public Properties getOptionProperties(String opt)
387387
{
388-
Properties props = new Properties();
388+
final Properties props = new Properties();
389389

390-
for (Option option : options)
390+
for (final Option option : options)
391391
{
392392
if (opt.equals(option.getOpt()) || opt.equals(option.getLongOpt()))
393393
{
394-
List<String> values = option.getValuesList();
394+
final List<String> values = option.getValuesList();
395395
if (values.size() >= 2)
396396
{
397397
// use the first 2 arguments as the key/value pair
@@ -415,7 +415,7 @@ else if (values.size() == 1)
415415
*/
416416
public String[] getArgs()
417417
{
418-
String[] answer = new String[args.size()];
418+
final String[] answer = new String[args.size()];
419419

420420
args.toArray(answer);
421421

@@ -492,10 +492,10 @@ public Iterator<Option> iterator()
492492
*/
493493
public Option[] getOptions()
494494
{
495-
Collection<Option> processed = options;
495+
final Collection<Option> processed = options;
496496

497497
// reinitialise array
498-
Option[] optionsArray = new Option[processed.size()];
498+
final Option[] optionsArray = new Option[processed.size()];
499499

500500
// return the array
501501
return processed.toArray(optionsArray);

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public CommandLine parse(Options options, String[] arguments, Properties propert
106106
expectedOpts = new ArrayList(options.getRequiredOptions());
107107

108108
// clear the data from the groups
109-
for (OptionGroup group : options.getOptionGroups())
109+
for (final OptionGroup group : options.getOptionGroups())
110110
{
111111
group.setSelected(null);
112112
}
@@ -115,7 +115,7 @@ public CommandLine parse(Options options, String[] arguments, Properties propert
115115

116116
if (arguments != null)
117117
{
118-
for (String argument : arguments)
118+
for (final String argument : arguments)
119119
{
120120
handleToken(argument);
121121
}
@@ -144,24 +144,24 @@ private void handleProperties(Properties properties) throws ParseException
144144
return;
145145
}
146146

147-
for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();)
147+
for (final Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();)
148148
{
149-
String option = e.nextElement().toString();
149+
final String option = e.nextElement().toString();
150150

151-
Option opt = options.getOption(option);
151+
final Option opt = options.getOption(option);
152152
if (opt == null)
153153
{
154154
throw new UnrecognizedOptionException("Default option wasn't defined", option);
155155
}
156156

157157
// if the option is part of a group, check if another option of the group has been selected
158-
OptionGroup group = options.getOptionGroup(opt);
159-
boolean selected = group != null && group.getSelected() != null;
158+
final OptionGroup group = options.getOptionGroup(opt);
159+
final boolean selected = group != null && group.getSelected() != null;
160160

161161
if (!cmd.hasOption(option) && !selected)
162162
{
163163
// get the value from the properties
164-
String value = properties.getProperty(option);
164+
final String value = properties.getProperty(option);
165165

166166
if (opt.hasArg())
167167
{
@@ -275,7 +275,7 @@ private boolean isNegativeNumber(String token)
275275
Double.parseDouble(token);
276276
return true;
277277
}
278-
catch (NumberFormatException e)
278+
catch (final NumberFormatException e)
279279
{
280280
return false;
281281
}
@@ -305,8 +305,8 @@ private boolean isShortOption(String token)
305305
}
306306

307307
// remove leading "-" and "=value"
308-
int pos = token.indexOf("=");
309-
String optName = pos == -1 ? token.substring(1) : token.substring(1, pos);
308+
final int pos = token.indexOf("=");
309+
final String optName = pos == -1 ? token.substring(1) : token.substring(1, pos);
310310
if (options.hasShortOption(optName))
311311
{
312312
return true;
@@ -327,8 +327,8 @@ private boolean isLongOption(String token)
327327
return false;
328328
}
329329

330-
int pos = token.indexOf("=");
331-
String t = pos == -1 ? token : token.substring(0, pos);
330+
final int pos = token.indexOf("=");
331+
final String t = pos == -1 ? token : token.substring(0, pos);
332332

333333
if (!options.getMatchingOptions(t).isEmpty())
334334
{
@@ -401,7 +401,7 @@ private void handleLongOption(String token) throws ParseException
401401
*/
402402
private void handleLongOptionWithoutEqual(String token) throws ParseException
403403
{
404-
List<String> matchingOpts = options.getMatchingOptions(token);
404+
final List<String> matchingOpts = options.getMatchingOptions(token);
405405
if (matchingOpts.isEmpty())
406406
{
407407
handleUnknownToken(currentToken);
@@ -428,13 +428,13 @@ else if (matchingOpts.size() > 1)
428428
*/
429429
private void handleLongOptionWithEqual(String token) throws ParseException
430430
{
431-
int pos = token.indexOf('=');
431+
final int pos = token.indexOf('=');
432432

433-
String value = token.substring(pos + 1);
433+
final String value = token.substring(pos + 1);
434434

435-
String opt = token.substring(0, pos);
435+
final String opt = token.substring(0, pos);
436436

437-
List<String> matchingOpts = options.getMatchingOptions(opt);
437+
final List<String> matchingOpts = options.getMatchingOptions(opt);
438438
if (matchingOpts.isEmpty())
439439
{
440440
handleUnknownToken(currentToken);
@@ -445,7 +445,7 @@ else if (matchingOpts.size() > 1)
445445
}
446446
else
447447
{
448-
Option option = options.getOption(matchingOpts.get(0));
448+
final Option option = options.getOption(matchingOpts.get(0));
449449

450450
if (option.acceptsArg())
451451
{
@@ -481,9 +481,9 @@ else if (matchingOpts.size() > 1)
481481
*/
482482
private void handleShortAndLongOption(String token) throws ParseException
483483
{
484-
String t = Util.stripLeadingHyphens(token);
484+
final String t = Util.stripLeadingHyphens(token);
485485

486-
int pos = t.indexOf('=');
486+
final int pos = t.indexOf('=');
487487

488488
if (t.length() == 1)
489489
{
@@ -512,7 +512,7 @@ else if (!options.getMatchingOptions(t).isEmpty())
512512
else
513513
{
514514
// look for a long prefix (-Xmx512m)
515-
String opt = getLongPrefix(t);
515+
final String opt = getLongPrefix(t);
516516

517517
if (opt != null && options.getOption(opt).acceptsArg())
518518
{
@@ -537,13 +537,13 @@ else if (isJavaProperty(t))
537537
else
538538
{
539539
// equal sign found (-xxx=yyy)
540-
String opt = t.substring(0, pos);
541-
String value = t.substring(pos + 1);
540+
final String opt = t.substring(0, pos);
541+
final String value = t.substring(pos + 1);
542542

543543
if (opt.length() == 1)
544544
{
545545
// -S=V
546-
Option option = options.getOption(opt);
546+
final Option option = options.getOption(opt);
547547
if (option != null && option.acceptsArg())
548548
{
549549
handleOption(option);
@@ -578,13 +578,13 @@ else if (isJavaProperty(opt))
578578
*/
579579
private String getLongPrefix(String token)
580580
{
581-
String t = Util.stripLeadingHyphens(token);
581+
final String t = Util.stripLeadingHyphens(token);
582582

583583
int i;
584584
String opt = null;
585585
for (i = t.length() - 2; i > 1; i--)
586586
{
587-
String prefix = t.substring(0, i);
587+
final String prefix = t.substring(0, i);
588588
if (options.hasLongOption(prefix))
589589
{
590590
opt = prefix;
@@ -600,8 +600,8 @@ private String getLongPrefix(String token)
600600
*/
601601
private boolean isJavaProperty(String token)
602602
{
603-
String opt = token.substring(0, 1);
604-
Option option = options.getOption(opt);
603+
final String opt = token.substring(0, 1);
604+
final Option option = options.getOption(opt);
605605

606606
return option != null && (option.getArgs() >= 2 || option.getArgs() == Option.UNLIMITED_VALUES);
607607
}
@@ -642,7 +642,7 @@ private void updateRequiredOptions(Option option) throws AlreadySelectedExceptio
642642
// if the option is in an OptionGroup make that option the selected option of the group
643643
if (options.getOptionGroup(option) != null)
644644
{
645-
OptionGroup group = options.getOptionGroup(option);
645+
final OptionGroup group = options.getOptionGroup(option);
646646

647647
if (group.isRequired())
648648
{
@@ -684,7 +684,7 @@ protected void handleConcatenatedOptions(String token) throws ParseException
684684
{
685685
for (int i = 1; i < token.length(); i++)
686686
{
687-
String ch = String.valueOf(token.charAt(i));
687+
final String ch = String.valueOf(token.charAt(i));
688688

689689
if (options.hasOption(ch))
690690
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public class GnuParser extends Parser
5050
@Override
5151
protected String[] flatten(Options options, String[] arguments, boolean stopAtNonOption)
5252
{
53-
List<String> tokens = new ArrayList<String>();
53+
final List<String> tokens = new ArrayList<String>();
5454

5555
boolean eatTheRest = false;
5656

5757
for (int i = 0; i < arguments.length; i++)
5858
{
59-
String arg = arguments[i];
59+
final String arg = arguments[i];
6060

6161
if ("--".equals(arg))
6262
{
@@ -69,7 +69,7 @@ else if ("-".equals(arg))
6969
}
7070
else if (arg.startsWith("-"))
7171
{
72-
String opt = Util.stripLeadingHyphens(arg);
72+
final String opt = Util.stripLeadingHyphens(arg);
7373

7474
if (options.hasOption(opt))
7575
{

0 commit comments

Comments
 (0)