/** * 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 the value of a given option in a given section or null if either * the section or the option don't exist. If a common section was defined * options are also looked up there if they're not present in the specific * section. * * @param section the section's name * @param option the option's name * @return the option's value * @throws NullPointerException any of the arguments is <code>null</code> */ public String get(String section, String option) { if (hasSection(section)) { Section sect = getSection(section); if (sect.hasOption(option)) { return sect.get(option); } if (this.commonName != null) { return getSection(this.commonName).get(option); } } return null; }
/** * 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; }
/** * Checks whether an option exists in a given section. Options in the * common section are assumed to not exist in particular sections, * unless they're overwritten. * * @param section the section's name * @param option the option's name * @return true if the given section has the option */ public boolean hasOption(String section, String option) { return hasSection(section) && getSection(section).hasOption(option); }