(@NotNull String path, @Nullable Object value)
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public void set(@NotNull String path, @Nullable Object value) { |
| 188 | Validate.notEmpty(path, "Cannot set to an empty path"); |
| 189 | |
| 190 | Configuration root = getRoot(); |
| 191 | if (root == null) { |
| 192 | throw new IllegalStateException("Cannot use section without a root"); |
| 193 | } |
| 194 | |
| 195 | final char separator = root.options().pathSeparator(); |
| 196 | // i1 is the leading (higher) index |
| 197 | // i2 is the trailing (lower) index |
| 198 | int i1 = -1, i2; |
| 199 | ConfigurationSection section = this; |
| 200 | while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1) { |
| 201 | String node = path.substring(i2, i1); |
| 202 | ConfigurationSection subSection = section.getConfigurationSection(node); |
| 203 | if (subSection == null) { |
| 204 | if (value == null) { |
| 205 | // no need to create missing sub-sections if we want to remove the value: |
| 206 | return; |
| 207 | } |
| 208 | section = section.createSection(node); |
| 209 | } else { |
| 210 | section = subSection; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | String key = path.substring(i2); |
| 215 | if (section == this) { |
| 216 | if (value == null) { |
| 217 | map.remove(key); |
| 218 | } else { |
| 219 | map.put(key, value); |
| 220 | } |
| 221 | } else { |
| 222 | section.set(key, value); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | @Nullable |
nothing calls this directly
no test coverage detected