/** * Remove the key if present. * If it were the last key for the section, the section is removed. * * @param sectionName the name of the section * @param key the key for the section * @return whether the key was present and removed */ public boolean remove(String sectionName, String key) { IniSection section = sectionMap.get(sectionName); if (section == null) { return false; } boolean changed = section.remove(key); sectionMap.remove(sectionName); list.remove(sectionName); return changed; }
/** * Remove the value if present. * If it were the last value for the key, the key is removed. * If it were the last key, the section is removed. * * @param sectionName the name of the section * @param key the key for the section * @param value the value for the key * @return whether the value was present and removed */ public boolean remove(String sectionName, String key, String value) { IniSection section = sectionMap.get(sectionName); if (section == null) { return false; } boolean changed = section.remove(key, value); if (changed) { if (section.isEmpty()) { sectionMap.remove(sectionName); list.remove(sectionName); } } return changed; }
private static void adjustHistory(IniSection config) { // Iterate over a copy of the keys so that we don't get // a concurrent modification exception when we remove matching keys // and when we add new keys List<String> keys = new ArrayList(config.getKeys()); for (String key : keys) { String value = config.get(key); ConfigEntryType type = ConfigEntryType.fromString(key); if (ConfigEntryType.HISTORY.equals(type)) { config.remove(key); int pos = key.indexOf('_'); value = key.substring(pos + 1) + ' ' + value; config.add(KEY_HISTORY, value); } } }