public ConfigurationSection createSection(String path) { Configuration root = getRoot(); if (root == null) { throw new IllegalStateException("Cannot create section without a root"); } final char separator = root.options().pathSeparator(); // i1 is the leading (higher) index // i2 is the trailing (lower) index int i1 = -1, i2; ConfigurationSection section = this; while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1) { String node = path.substring(i2, i1); ConfigurationSection subSection = section.getConfigurationSection(node); if (subSection == null) { section = section.createSection(node); } else { section = subSection; } } String key = path.substring(i2); if (section == this) { ConfigurationSection result = new MemorySection(this, key); map.put(key, result); return result; } return section.createSection(key); }
public ConfigurationSection createSection(String path) { if (path == null) { throw new IllegalArgumentException("Path cannot be null"); } else if (path.length() == 0) { throw new IllegalArgumentException("Cannot create section at empty path"); } String[] split = path.split(Pattern.quote(Character.toString(getRoot().options().pathSeparator()))); ConfigurationSection section = this; 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) { ConfigurationSection result = new MemorySection(this, key); map.put(key, result); return result; } else { return section.createSection(key); } }
public void set(String path, Object value) { Configuration root = getRoot(); if (root == null) { throw new IllegalStateException("Cannot use section without a root"); } final char separator = root.options().pathSeparator(); // i1 is the leading (higher) index // i2 is the trailing (lower) index int i1 = -1, i2; ConfigurationSection section = this; while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1) { String node = path.substring(i2, i1); ConfigurationSection subSection = section.getConfigurationSection(node); if (subSection == null) { section = section.createSection(node); } else { section = subSection; } } String key = path.substring(i2); if (section == this) { if (value == null) { map.remove(key); } else { map.put(key, value); } } else { section.set(key, value); } }
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; }