diff --git a/implementation/src/main/java/io/smallrye/config/KeyMap.java b/implementation/src/main/java/io/smallrye/config/KeyMap.java index df35f6611..2ea85c7db 100644 --- a/implementation/src/main/java/io/smallrye/config/KeyMap.java +++ b/implementation/src/main/java/io/smallrye/config/KeyMap.java @@ -4,7 +4,6 @@ import java.util.HashMap; import java.util.IdentityHashMap; import java.util.Iterator; -import java.util.Map; import java.util.Set; import java.util.function.BiFunction; import java.util.function.Function; @@ -257,29 +256,4 @@ public StringBuilder toString(StringBuilder b) { public String toString() { return toString(new StringBuilder()).toString(); } - - public Map toMap() { - final Map map = new HashMap<>(); - unwrap(this, "", map); - return map; - } - - private void unwrap(KeyMap keyMap, String key, Map map) { - for (String path : keyMap.keySet()) { - final KeyMap nested = keyMap.get(path); - final String nestedKey = key.length() == 0 ? path : key + "." + path; - if (nested.any != null) { - map.put(nestedKey + ".*", nested.any.getRootValue()); - unwrap(nested.any, nestedKey + ".*", map); - } - if (!nested.hasRootValue()) { - unwrap(nested, nestedKey, map); - } else { - map.put(nestedKey, nested.getRootValue()); - if (!nested.keySet().isEmpty()) { - unwrap(nested, nestedKey, map); - } - } - } - } } diff --git a/implementation/src/main/java/io/smallrye/config/KeyMapBackedConfigSource.java b/implementation/src/main/java/io/smallrye/config/KeyMapBackedConfigSource.java index 0a24d1959..ed28d3ba3 100644 --- a/implementation/src/main/java/io/smallrye/config/KeyMapBackedConfigSource.java +++ b/implementation/src/main/java/io/smallrye/config/KeyMapBackedConfigSource.java @@ -1,5 +1,6 @@ package io.smallrye.config; +import java.util.Collections; import java.util.Map; import org.eclipse.microprofile.config.spi.ConfigSource; @@ -23,7 +24,7 @@ public KeyMapBackedConfigSource(final String name, final int ordinal, final KeyM @Override public Map getProperties() { - return properties.toMap(); + return Collections.emptyMap(); } @Override diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java index e14c9b49e..748100705 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java @@ -338,7 +338,7 @@ public SmallRyeConfig build() { @Override public Map getProperties() { - return new HashMap<>(); + return Collections.emptyMap(); } @Override diff --git a/implementation/src/test/java/io/smallrye/config/KeyMapBackedConfigSourceTest.java b/implementation/src/test/java/io/smallrye/config/KeyMapBackedConfigSourceTest.java index 7b8272ba6..411dadeff 100644 --- a/implementation/src/test/java/io/smallrye/config/KeyMapBackedConfigSourceTest.java +++ b/implementation/src/test/java/io/smallrye/config/KeyMapBackedConfigSourceTest.java @@ -8,7 +8,6 @@ import org.junit.jupiter.api.Test; class KeyMapBackedConfigSourceTest { - @Test void getProperties() { KeyMap map = new KeyMap<>(); @@ -17,12 +16,9 @@ void getProperties() { map.findOrAdd("root.foo.bar.*").putRootValue("baz"); map.findOrAdd("root.foo.bar.*.baz").putRootValue("anything"); - final ConfigSource source = getSource(map); - final Map properties = source.getProperties(); - assertTrue(properties.containsKey("root.foo")); - assertTrue(properties.containsKey("root.foo.bar")); - assertTrue(properties.containsKey("root.foo.bar.*")); - assertTrue(properties.containsKey("root.foo.bar.*.baz")); + ConfigSource source = getSource(map); + Map properties = source.getProperties(); + assertTrue(properties.isEmpty()); } @Test @@ -33,7 +29,7 @@ void getValue() { map.findOrAdd("root.foo.bar.*").putRootValue("baz"); map.findOrAdd("root.foo.bar.*.baz").putRootValue("anything"); - final ConfigSource source = getSource(map); + ConfigSource source = getSource(map); assertEquals("bar", source.getValue("root.foo")); assertEquals("baz", source.getValue("root.foo.bar")); assertEquals("baz", source.getValue("root.foo.bar.x")); diff --git a/implementation/src/test/java/io/smallrye/config/KeyMapTest.java b/implementation/src/test/java/io/smallrye/config/KeyMapTest.java index 2e200196c..0a93065c9 100644 --- a/implementation/src/test/java/io/smallrye/config/KeyMapTest.java +++ b/implementation/src/test/java/io/smallrye/config/KeyMapTest.java @@ -3,7 +3,6 @@ import static java.util.stream.Collectors.toList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashMap; import java.util.Map; @@ -106,26 +105,6 @@ void empty() { assertEquals("bar", map.findRootValue(".foo")); } - @Test - void unwrap() { - KeyMap map = new KeyMap<>(); - map.findOrAdd("root.foo").putRootValue("bar"); - map.findOrAdd("root.foo.bar").putRootValue("baz"); - map.findOrAdd("root.foo.bar.*").putRootValue("baz"); - map.findOrAdd("root.foo.bar.*.baz").putRootValue("anything"); - - Map properties = map.toMap(); - assertTrue(properties.containsKey("root.foo")); - assertTrue(properties.containsKey("root.foo.bar")); - assertTrue(properties.containsKey("root.foo.bar.*")); - assertTrue(properties.containsKey("root.foo.bar.*.baz")); - - assertEquals("bar", properties.get("root.foo")); - assertEquals("baz", properties.get("root.foo.bar")); - assertEquals("baz", properties.get("root.foo.bar.*")); - assertEquals("anything", properties.get("root.foo.bar.*.baz")); - } - @Test void string() { KeyMap map = new KeyMap<>();