6060 */
6161package org .apache .commons .cli ;
6262
63+ import java .util .ArrayList ;
6364import java .util .Collection ;
6465import java .util .HashMap ;
6566import java .util .Iterator ;
8081 *
8182 * @author bob mcwhirter (bob @ werken.com)
8283 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
83- * @author John Keyes (jbjk at mac .com)
84+ * @author John Keyes (john at integralsource .com)
8485 */
8586public class CommandLine {
8687
@@ -92,6 +93,8 @@ public class CommandLine {
9293
9394 /** Map of unique options for ease to get complete list of options */
9495 private Map hashcodeMap = new HashMap ();
96+ private List optionList = new ArrayList ();
97+ private List keyList = new ArrayList ();
9598
9699 /** the processed options */
97100 private Option [] optionsArray ;
@@ -282,13 +285,16 @@ void addArg(String arg) {
282285 *
283286 * @param opt the processed option
284287 */
285- void setOpt ( Option opt ) {
288+ void addOption ( Option opt ) {
286289 hashcodeMap .put ( new Integer ( opt .hashCode () ), opt );
287290
291+ optionList .add ( opt );
288292 String key = opt .getOpt ();
289293 if ( " " .equals (key ) ) {
290294 key = opt .getLongOpt ();
291295 }
296+ keyList .add ( key );
297+
292298 if ( options .get ( key ) != null ) {
293299 ((java .util .List )options .get ( key )).add ( opt );
294300 }
@@ -323,4 +329,14 @@ public Option[] getOptions( ) {
323329 return (Option []) processed .toArray ( optionsArray );
324330 }
325331
332+ public Option [] getOptions2 () {
333+ System .out .println ( "--2--" );
334+ Collection processed = optionList ;
335+ // reinitialise array
336+ optionsArray = new Option [ processed .size () ];
337+
338+ // return the array
339+ return (Option []) processed .toArray ( optionsArray );
340+ }
341+
326342}
0 commit comments