Skip to content

Commit

Permalink
Further changes as requested
Browse files Browse the repository at this point in the history
* Removed object handling while building the array
* inlined property names streaming.
  • Loading branch information
ikonkere committed Sep 5, 2019
1 parent df027b4 commit 14f16c6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,4 @@ $RECYCLE.BIN/
*.lnk


/test-output/
12 changes: 1 addition & 11 deletions src/main/java/com/kumuluz/ee/config/microprofile/ConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -155,20 +154,11 @@ private <T> Converter<T> getConverter(Class asType) {

@Override
public Iterable<String> 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<ConfigSource> 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<String> asStream(ConfigSource arg0) {
return arg0.getPropertyNames().stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -61,12 +60,15 @@ public int getOrdinal() {
@Override
public String getValue(String s) {
String val = configurationSource.get(s).orElse(null);
Optional<Integer> 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<Integer> 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;
Expand Down Expand Up @@ -112,16 +114,9 @@ private String buildArray(String propertyName, int size) {
String prefix = String.format("%s[%d]", propertyName, i);
Optional<List<String>> 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<String, String> map = new HashMap<>();
buildPropertiesMap(map, prefix);

Map<String, String> 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<String> item = this.configurationSource.get(String.format("%s[%d]", propertyName, i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 14f16c6

Please sign in to comment.