From 14f16c6bab2443a7c5af209ce99b5a88138ddb4f Mon Sep 17 00:00:00 2001 From: Yog Sothoth Date: Thu, 5 Sep 2019 14:13:37 +0300 Subject: [PATCH] Further changes as requested * Removed object handling while building the array * inlined property names streaming. --- .gitignore | 1 + .../ee/config/microprofile/ConfigImpl.java | 12 +-------- .../adapters/ConfigSourceAdapter.java | 27 ++++++++----------- .../tests/ArrayInjectionTest.java | 2 +- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 72a7d81..f95ed8f 100644 --- a/.gitignore +++ b/.gitignore @@ -157,3 +157,4 @@ $RECYCLE.BIN/ *.lnk +/test-output/ diff --git a/src/main/java/com/kumuluz/ee/config/microprofile/ConfigImpl.java b/src/main/java/com/kumuluz/ee/config/microprofile/ConfigImpl.java index 4b88c97..f713309 100644 --- a/src/main/java/com/kumuluz/ee/config/microprofile/ConfigImpl.java +++ b/src/main/java/com/kumuluz/ee/config/microprofile/ConfigImpl.java @@ -31,7 +31,6 @@ import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.spi.ConfigSource; @@ -155,20 +154,11 @@ private Converter getConverter(Class asType) { @Override public Iterable getPropertyNames() { - return this.configSources.stream().flatMap(this::asStream).collect(Collectors.toSet()); + return this.configSources.stream().flatMap(e -> e.getPropertyNames().stream()).collect(Collectors.toSet()); } @Override public Iterable getConfigSources() { return this.configSources; } - - /** - * Streams this config source as property names - * @param arg0 config source to stream - * @return stream of property names, never null - */ - private Stream asStream(ConfigSource arg0) { - return arg0.getPropertyNames().stream(); - } } \ No newline at end of file diff --git a/src/main/java/com/kumuluz/ee/config/microprofile/adapters/ConfigSourceAdapter.java b/src/main/java/com/kumuluz/ee/config/microprofile/adapters/ConfigSourceAdapter.java index 234e3f8..49dd13c 100644 --- a/src/main/java/com/kumuluz/ee/config/microprofile/adapters/ConfigSourceAdapter.java +++ b/src/main/java/com/kumuluz/ee/config/microprofile/adapters/ConfigSourceAdapter.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.stream.Collectors; import org.eclipse.microprofile.config.spi.ConfigSource; @@ -61,12 +60,15 @@ public int getOrdinal() { @Override public String getValue(String s) { String val = configurationSource.get(s).orElse(null); - Optional listSize = this.configurationSource.getListSize(s); - - //this is a list or an array - if (listSize.isPresent()) { - //we ignore the returned value and build the array - return buildArray(s, listSize.get()); + + if (val != null) { + Optional listSize = this.configurationSource.getListSize(s); + + //this is a list or an array + if (listSize.isPresent()) { + //we ignore the returned value and build the array + return buildArray(s, listSize.get()); + } } return val; @@ -112,16 +114,9 @@ private String buildArray(String propertyName, int size) { String prefix = String.format("%s[%d]", propertyName, i); Optional> objectKeys = this.configurationSource.getMapKeys(prefix); - //array item is an object, so we just toString() it + //array item is an object, so we just omit it if (objectKeys.isPresent()) { - Map map = new HashMap<>(); - buildPropertiesMap(map, prefix); - - Map object = - map.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().substring(prefix.length() + 1), - e -> e.getValue())); - - sb.append(object.toString().replaceAll(",", "\\\\,")); + sb.append(""); } else { Optional item = this.configurationSource.get(String.format("%s[%d]", propertyName, i)); diff --git a/src/test/java/com/kumuluz/ee/config/microprofile/tests/ArrayInjectionTest.java b/src/test/java/com/kumuluz/ee/config/microprofile/tests/ArrayInjectionTest.java index fa6409a..1137a61 100644 --- a/src/test/java/com/kumuluz/ee/config/microprofile/tests/ArrayInjectionTest.java +++ b/src/test/java/com/kumuluz/ee/config/microprofile/tests/ArrayInjectionTest.java @@ -76,7 +76,7 @@ public static JavaArchive deploy() { private String arrayItemParam; private static final String[] TEST_TARGET = - new String[]{"one ", " two", " [three, four] ", "{five.six=seven, five.eight=nine}"}; + new String[]{"one ", " two", " [three, four] "}; @Test public void testNotParsingDelimeters() {