diff options
3 files changed, 36 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/configuration/ConfigurationSection.java b/src/main/java/org/bukkit/configuration/ConfigurationSection.java index 1bd7fb51..166f2a65 100644 --- a/src/main/java/org/bukkit/configuration/ConfigurationSection.java +++ b/src/main/java/org/bukkit/configuration/ConfigurationSection.java @@ -59,6 +59,25 @@ public interface ConfigurationSection { public boolean contains(String path); /** + * Checks if this {@link ConfigurationSection} contains the given path. + * <p> + * If the value for the requested path does not exist, the boolean parameter + * of true has been specified, a default value for the path exists, this + * will return true. + * <p> + * If a boolean parameter of false has been specified, true will only be + * returned if there is a set value for the specified path. + * + * @param path Path to check for existence. + * @param ignoreDefault Whether or not to ignore if a default value for the + * specified path exists. + * @return True if this section contains the requested path, or if a default + * value exist and the boolean parameter for this method is true. + * @throws IllegalArgumentException Thrown when path is null. + */ + public boolean contains(String path, boolean ignoreDefault); + + /** * Checks if this {@link ConfigurationSection} has a value set for the * given path. * <p> diff --git a/src/main/java/org/bukkit/configuration/MemorySection.java b/src/main/java/org/bukkit/configuration/MemorySection.java index f180bf5f..3b92c644 100644 --- a/src/main/java/org/bukkit/configuration/MemorySection.java +++ b/src/main/java/org/bukkit/configuration/MemorySection.java @@ -103,7 +103,11 @@ public class MemorySection implements ConfigurationSection { } public boolean contains(String path) { - return get(path) != null; + return contains(path, false); + } + + public boolean contains(String path, boolean ignoreDefault) { + return ((ignoreDefault) ? get(path, null) : get(path)) != null; } public boolean isSet(String path) { diff --git a/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java b/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java index 6dab4779..cb818418 100644 --- a/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java +++ b/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java @@ -91,6 +91,18 @@ public abstract class ConfigurationSectionTest { assertTrue(section.contains("exists")); assertFalse(section.contains("doesnt-exist")); + + assertTrue(section.contains("exists", true)); + assertTrue(section.contains("exists", false)); + + assertFalse(section.contains("doesnt-exist", true)); + assertFalse(section.contains("doesnt-exist", false)); + + section.addDefault("doenst-exist-two", true); + section.set("doenst-exist-two", null); + + assertFalse(section.contains("doenst-exist-two", true)); + assertTrue(section.contains("doenst-exist-two", false)); } @Test |