Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#63] A multi-value config get operation #64

Merged
merged 2 commits into from
Dec 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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