mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-15 04:05:50 -07:00
Add method to check configuration path existence, ignoring defaults.
By: FakeNeth <cneth97@gmail.com>
This commit is contained in:
@@ -58,6 +58,25 @@ public interface ConfigurationSection {
|
|||||||
*/
|
*/
|
||||||
public boolean contains(String path);
|
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
|
* Checks if this {@link ConfigurationSection} has a value set for the
|
||||||
* given path.
|
* given path.
|
||||||
|
@@ -103,7 +103,11 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(String path) {
|
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) {
|
public boolean isSet(String path) {
|
||||||
|
@@ -91,6 +91,18 @@ public abstract class ConfigurationSectionTest {
|
|||||||
|
|
||||||
assertTrue(section.contains("exists"));
|
assertTrue(section.contains("exists"));
|
||||||
assertFalse(section.contains("doesnt-exist"));
|
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
|
@Test
|
||||||
|
Reference in New Issue
Block a user