From 6563a9241bce93ca99be5eded5f6904c3ba872a6 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 21 Aug 2016 09:10:23 +1000 Subject: [PATCH] #1936: Configuration#contains(Ljava/lang/String;)Z --- .../src/main/java/net/md_5/bungee/config/Configuration.java | 5 +++++ .../java/net/md_5/bungee/config/YamlConfigurationTest.java | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/config/src/main/java/net/md_5/bungee/config/Configuration.java b/config/src/main/java/net/md_5/bungee/config/Configuration.java index a7ddf3a3..2b29614a 100644 --- a/config/src/main/java/net/md_5/bungee/config/Configuration.java +++ b/config/src/main/java/net/md_5/bungee/config/Configuration.java @@ -91,6 +91,11 @@ public final class Configuration return ( val != null ) ? (T) val : def; } + public boolean contains(String path) + { + return get( path, null ) != null; + } + public Object get(String path) { return get( path, getDefault( path ) ); diff --git a/config/src/test/java/net/md_5/bungee/config/YamlConfigurationTest.java b/config/src/test/java/net/md_5/bungee/config/YamlConfigurationTest.java index c400b92f..589d3ee4 100644 --- a/config/src/test/java/net/md_5/bungee/config/YamlConfigurationTest.java +++ b/config/src/test/java/net/md_5/bungee/config/YamlConfigurationTest.java @@ -94,6 +94,12 @@ public class YamlConfigurationTest conf.set( "other.new.section", "bar" ); Assert.assertEquals( "bar", conf.get( "other.new.section" ) ); + + Assert.assertTrue( conf.contains( "customer.given" ) ); + Assert.assertTrue( customer.contains( "given" ) ); + + Assert.assertFalse( conf.contains( "customer.foo" ) ); + Assert.assertFalse( customer.contains( "foo" ) ); } @Test