mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 01:37:35 +01:00
Add method to check configuration path existence, ignoring defaults.
By: FakeNeth <cneth97@gmail.com>
This commit is contained in:
parent
51bdeb679c
commit
640346e011
@ -58,6 +58,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.
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user