public void set(String path, Object value) { String[] split = path.split(Pattern.quote(Character.toString(getRoot().options().pathSeparator()))); ConfigurationSection section = this; if (path.length() == 0) { throw new IllegalArgumentException("Cannot set to an empty path"); } for (int i = 0; i < split.length - 1; i++) { ConfigurationSection last = section; section = last.getConfigurationSection(split[i]); if (section == null) { section = last.createSection(split[i]); } } String key = split[split.length - 1]; if (section == this) { if (value == null) { map.remove(key); } else { map.put(key, value); } } else { section.set(key, value); } }
public ConfigurationSection createSection(String path, Map<?, ?> map) { ConfigurationSection section = createSection(path); for (Map.Entry<?, ?> entry : map.entrySet()) { if (entry.getValue() instanceof Map) { section.createSection(entry.getKey().toString(), (Map<?, ?>) entry.getValue()); } else { section.set(entry.getKey().toString(), entry.getValue()); } } return section; }