6464import java .util .Collection ;
6565import java .util .Map ;
6666import java .util .HashMap ;
67- import java .util .List ;
68- import java .util .ArrayList ;
6967import java .util .Iterator ;
7068import java .util .Collections ;
7169
8684 */
8785public 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