…lines 1–44 unchanged (44 lines)
45 private final Map values = new HashMap();
46 private final Map switches = new HashMap();
47 private final Map defaultValues = new HashMap();
48 private final Map defaultSwitches = new HashMap();
49 private final List normalised;
50 private final Set prefixes;
51 private Option currentOption;
52 private String checkForOption;
53
54 /**
55 * Creates a new WriteableCommandLineImpl rooted on the specified Option, to
56 * hold the parsed arguments.
57 *
58 * @param rootOption the CommandLine's root Option
59 * @param arguments the arguments this CommandLine represents
60 */
61 public WriteableCommandLineImpl(final Option rootOption,
62 final List arguments) {
63 this.prefixes = rootOption.getPrefixes();
64 this.normalised = arguments;
65 setCurrentOption(rootOption);
66 }
67
68 public Option getCurrentOption() {
69 return currentOption;
70 }
71
72 public void setCurrentOption(Option currentOption) {
73 this.currentOption = currentOption;
74 }
75
76 public void addOption(Option option) {
77 options.add(option);
78 nameToOption.put(option.getPreferredName(), option);
79
80 for (Iterator i = option.getTriggers().iterator(); i.hasNext();) {
…lines 81–236 unchanged (156 lines)
237 *
238 * @param trigger the command line element to test
239 * @return a flag whether this element seems to be an option
240 */
241 public boolean looksLikeOption(final String trigger)
242 {
243 if (checkForOption != null)
244 {
245 // this is a reentrant call
246 return !checkForOption.equals(trigger);
247 }
248
249 checkForOption = trigger;
250 try
251 {
252 for (final Iterator i = prefixes.iterator(); i.hasNext();)
253 {
254 final String prefix = (String) i.next();
255
256 if (trigger.startsWith(prefix))
257 {
258 if (getCurrentOption().canProcess(this, trigger)
259 || getCurrentOption().findOption(trigger) != null)
260 {
261 return true;
262 }
263 }
264 }
265
266 return false;
267 }
268 finally
269 {
270 checkForOption = null;
271 }
272 }
273
274 public String toString() {
275 final StringBuffer buffer = new StringBuffer();
276
277 // need to add group header
…lines 278–325 unchanged (48 lines)