@@ -89,8 +89,11 @@ public class CommandLine {
8989 /** the unrecognised options/arguments */
9090 private List args = new LinkedList ();
9191
92- /** the recognised options */
93- private Map options = new HashMap ();
92+ /** the processed options */
93+ private Map options = new HashMap ();
94+
95+ /** Map of unique options for ease to get complete list of options */
96+ private Map hashcodeMap = new HashMap ();
9497
9598 /** the processed options */
9699 private Option [] optionsArray ;
@@ -125,7 +128,8 @@ public boolean hasOption( char opt ) {
125128 */
126129 public Object getOptionObject ( String opt ) {
127130 String res = getOptionValue ( opt );
128- Object type = ((Option )options .get ( opt )).getType ();
131+
132+ Object type = ((Option )((List )options .get (opt )).iterator ().next ()).getType ();
129133 return res == null ? null : TypeHandler .createValue (res , type );
130134 }
131135
@@ -143,7 +147,8 @@ public Object getOptionObject( char opt ) {
143147 * @return Value of the argument if option is set, and has an argument, else null.
144148 */
145149 public String getOptionValue ( String opt ) {
146- return (String )((Option )options .get ( opt )).getValue ();
150+ String [] values = getOptionValues (opt );
151+ return (values == null ) ? null : values [0 ];
147152 }
148153
149154 /** <p>Retrieve the argument, if any, of an option.</p>
@@ -161,7 +166,16 @@ public String getOptionValue( char opt ) {
161166 * @return An array of values if the option is set, and has an argument, else null.
162167 */
163168 public String [] getOptionValues ( String opt ) {
164- return (String [])((Option )options .get ( opt )).getValues ();
169+ List values = new java .util .ArrayList ();
170+
171+ List opts = (List )options .get ( opt );
172+ Iterator iter = opts .iterator ();
173+
174+ while ( iter .hasNext () ) {
175+ Option optt = (Option )iter .next ();
176+ values .addAll ( optt .getValuesList () );
177+ }
178+ return (values .size () == 0 ) ? null : (String [])values .toArray (new String []{});
165179 }
166180
167181 /** <p>Retrieves the array of values, if any, of an option.</p>
@@ -212,10 +226,14 @@ public List getArgList() {
212226 return args ;
213227 }
214228
215- /** <p>Dump state, suitable for debugging.</p>
229+ /**
230+ * jkeyes
231+ * - commented out until it is implemented properly
232+ * <p>Dump state, suitable for debugging.</p>
216233 *
217234 * @return Stringified form of this object
218235 */
236+ /*
219237 public String toString() {
220238 StringBuffer buf = new StringBuffer();
221239
@@ -227,7 +245,8 @@ public String toString() {
227245
228246 return buf.toString();
229247 }
230-
248+ */
249+
231250 /**
232251 * <p>Add left-over unrecognized option/argument.</p>
233252 *
@@ -244,7 +263,15 @@ void addArg(String arg) {
244263 * @param opt the processed option
245264 */
246265 void setOpt ( Option opt ) {
247- options .put ( opt .getOpt (), opt );
266+ hashcodeMap .put ( new Integer ( opt .hashCode () ), opt );
267+
268+ if ( options .get ( opt .getOpt () ) != null ) {
269+ ((java .util .List )options .get ( opt .getOpt () )).add ( opt );
270+ }
271+ else {
272+ options .put ( opt .getOpt (), new java .util .ArrayList () );
273+ ((java .util .List )options .get ( opt .getOpt () ) ).add ( opt );
274+ }
248275 }
249276
250277 /**
@@ -254,7 +281,7 @@ void setOpt( Option opt ) {
254281 * members of this {@link CommandLine}
255282 */
256283 public Iterator iterator ( ) {
257- return options .values ().iterator ();
284+ return hashcodeMap .values ().iterator ();
258285 }
259286
260287 /**
@@ -263,7 +290,7 @@ public Iterator iterator( ) {
263290 * @return an array of the processed {@link Option}s.
264291 */
265292 public Option [] getOptions ( ) {
266- Collection processed = options .values ();
293+ Collection processed = hashcodeMap .values ();
267294
268295 // reinitialise array
269296 optionsArray = new Option [ processed .size () ];
0 commit comments