Skip to content

Commit

Permalink
Merge pull request #64 from dmlloyd/multi
Browse files Browse the repository at this point in the history
[#63] A multi-value config get operation
  • Loading branch information
kenfinnigan authored Dec 14, 2018
2 parents 2bddea4 + 852fc34 commit 8369341
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.Set;
import java.util.function.IntFunction;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigSource;
Expand All @@ -50,6 +52,22 @@ protected SmallRyeConfig(List<ConfigSource> configSources, Map<Type, Converter>
this.converters.putAll(converters);
}

// no @Override
public <T, C extends Collection<T>> C getValues(String name, Class<T> itemClass, IntFunction<C> 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> T getValue(String name, Class<T> aClass) {
for (ConfigSource configSource : configSources) {
Expand Down

0 comments on commit 8369341

Please sign in to comment.