Skip to content

Commit 5e98762

Browse files
author
John Keyes
committed
removed use of options list, reduced concatenation
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@129781 13f79535-47bb-0310-9956-ffa450edef68
1 parent 929f397 commit 5e98762

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

src/java/org/apache/commons/cli/Options.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@
6464
import java.util.Collection;
6565
import java.util.Map;
6666
import java.util.HashMap;
67-
import java.util.List;
68-
import java.util.ArrayList;
6967
import java.util.Iterator;
7068
import java.util.Collections;
7169

@@ -86,9 +84,6 @@
8684
*/
8785
public class Options {
8886

89-
/** the list of options */
90-
private List options = new ArrayList();
91-
9287
/** a map of the options with the character key */
9388
private Map shortOpts = new HashMap();
9489

@@ -206,9 +201,10 @@ public Options addOption(String opt, String longOpt, boolean hasArg, String desc
206201
* <p>Adds an option instance</p>
207202
*
208203
* @param opt the option that is to be added
204+
* @return the resulting Options instance
209205
*/
210206
public Options addOption(Option opt) {
211-
String shortOptStr = "-" + opt.getOpt();
207+
String shortOpt = "-" + opt.getOpt();
212208

213209
// add it to the long option list
214210
if ( opt.hasLongOpt() ) {
@@ -217,21 +213,20 @@ public Options addOption(Option opt) {
217213

218214
// if the option is required add it to the required list
219215
if ( opt.isRequired() ) {
220-
requiredOpts.put( "-" + opt.getOpt(), opt );
216+
requiredOpts.put( shortOpt, opt );
221217
}
222218

223-
shortOpts.put( "-" + opt.getOpt(), opt );
219+
shortOpts.put( shortOpt, opt );
224220

225-
options.add( opt );
226221
return this;
227222
}
228223

229224
/** <p>Retrieve a read-only list of options in this set</p>
230225
*
231-
* @return read-only List of {@link Option} objects in this descriptor
226+
* @return read-only Collection of {@link Option} objects in this descriptor
232227
*/
233-
public List getOptions() {
234-
return Collections.unmodifiableList(options);
228+
public Collection getOptions() {
229+
return Collections.unmodifiableCollection( shortOpts.values() );
235230
}
236231

237232
/** <p>Returns the required options as a

0 commit comments

Comments
 (0)