/** * Checks whether a given option exists in this section. * * @param name the name of the option to test for * @return true if the option exists in this section */ public boolean hasOption(String name) { return this.options.containsKey(normOption(name)); }
/** * Removes an option if it exists. * * @param option the name of the option * @return <code>true</code> if the option was actually removed */ public boolean remove(String option) { String normed = normOption(option); if (hasOption(normed)) { this.lines.remove(getOption(normed)); this.options.remove(normed); return true; } else { return false; } }
/** * Sets an option's value and creates the option if it doesn't exist. * * @param option the option's name * @param value the option's value * @param delim the delimiter between name and value for this option * @throws IllegalArgumentException the option name is illegal, * ie contains a '=' character or consists only of white space */ public void set(String option, String value, char delim) { String normed = normOption(option); if (hasOption(normed)) { getOption(normed).set(value); } else { // Option constructor might throw IllegalArgumentException Option opt = new Option(normed, value, delim, this.optionFormat); this.options.put(normed, opt); this.lines.add(opt); } }
/** * Returns an option's value. * * @param option the name of the option * @return the requested option's value or <code>null</code> if no * option with the specified name exists */ public String get(String option) { String normed = normOption(option); if (hasOption(normed)) { return getOption(normed).value(); } return null; }