Added createSection(String path, Map<String, object> map)

By: Feildmaster <admin@feildmaster.com>
This commit is contained in:
Bukkit/Spigot 2011-11-01 22:04:48 -05:00
parent 04ccdf16fd
commit 867d2bc046
4 changed files with 39 additions and 1 deletions

View file

@ -164,6 +164,17 @@ public interface ConfigurationSection {
* @return Newly created section
*/
public ConfigurationSection createSection(String path);
/**
* Creates a {@link ConfigurationSection} at the specified path, with specified values.
* <p>
* Any value that was previously set at this path will be overwritten. If the
* previous value was itself a {@link ConfigurationSection}, it will be orphaned.
*
* @param path Path to create the section at.
* @return Newly created section
*/
public ConfigurationSection createSection(String path, Map<String, Object> map);
// Primitives
/**

View file

@ -266,6 +266,20 @@ public class MemorySection implements ConfigurationSection {
return section.createSection(key);
}
}
public ConfigurationSection createSection(String path, Map<String, Object> map) {
ConfigurationSection section = createSection(path);
for(Map.Entry<String, Object> entry : map.entrySet()) {
if(entry.getValue() instanceof Map) {
section.createSection(entry.getKey(), (Map<String, Object>)entry.getValue());
} else {
section.set(entry.getKey(), entry.getValue());
}
}
return section;
}
// Primitives
public String getString(String path) {

View file

@ -3,6 +3,7 @@ package org.bukkit.configuration;
import org.bukkit.Material;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.inventory.ItemStack;
@ -182,6 +183,19 @@ public abstract class ConfigurationSectionTest {
assertEquals("subsection", subsection.getName());
}
@Test
public void testSectionMap() {
ConfigurationSection config = getConfigurationSection();
Map<String, Object> testMap = new LinkedHashMap<String, Object>();
testMap.put("string", "Hello World");
testMap.put("integer", 15);
config.createSection("test.path", testMap);
assertEquals(testMap, config.getConfigurationSection("test.path").getValues(false));
}
@Test
public void testGetString_String() {
ConfigurationSection section = getConfigurationSection();

View file

@ -1,7 +1,6 @@
package org.bukkit.configuration;
import java.util.LinkedHashMap;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;