From 6a5cdf5cb38ce11bc00c07730001e837df90002e Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Thu, 13 Dec 2018 14:49:07 -0600 Subject: [PATCH] [#63] A multi-value config get operation --- .../io/smallrye/config/SmallRyeConfig.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java index 431cebcf8..cfb5b5a04 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java @@ -21,6 +21,7 @@ import java.io.Serializable; import java.lang.reflect.Array; import java.lang.reflect.Type; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -28,6 +29,7 @@ import java.util.NoSuchElementException; import java.util.Optional; import java.util.Set; +import java.util.function.IntFunction; import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.spi.ConfigSource; @@ -47,6 +49,22 @@ protected SmallRyeConfig(List configSources, Map this.converters.putAll(converters); } + // no @Override + public > C getValues(String name, Class itemClass, IntFunction collectionFactory) { + for (ConfigSource configSource : configSources) { + String value = configSource.getValue(name); + if (value != null) { + String[] itemStrings = StringUtil.split(value); + final C collection = collectionFactory.apply(itemStrings.length); + for (String itemString : itemStrings) { + collection.add(convert(itemString, itemClass)); + } + return collection; + } + } + return collectionFactory.apply(0); + } + @Override public T getValue(String name, Class aClass) { for (ConfigSource configSource : configSources) {