diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigSources.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigSources.java index 17deef2a2..5e545239a 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigSources.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigSources.java @@ -1,8 +1,9 @@ package io.smallrye.config; +import static java.util.Collections.emptyIterator; + import java.io.Serializable; import java.util.ArrayList; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -43,16 +44,36 @@ public ConfigValue getValue(final ConfigSourceInterceptorContext context, final @Override public Iterator iterateNames(final ConfigSourceInterceptorContext context) { - final Set names = new HashSet<>(); - for (final ConfigValueConfigSource configSource : configSources) { - final Set propertyNames = configSource.getPropertyNames(); - if (propertyNames != null) { - names.addAll(propertyNames); + return new Iterator<>() { + final Iterator configSourceIterator = configSources.iterator(); + Iterator propertiesIterator = context.iterateNames(); + + @Override + public boolean hasNext() { + if (propertiesIterator.hasNext()) { + return true; + } else { + propertiesIterator = nextConfigSource(); + if (propertiesIterator.hasNext()) { + return true; + } else if (configSourceIterator.hasNext()) { + return hasNext(); + } else { + return false; + } + } } - } - Iterator iter = context.iterateNames(); - iter.forEachRemaining(names::add); - return names.iterator(); + + @Override + public String next() { + return propertiesIterator.next(); + } + + private Iterator nextConfigSource() { + return configSourceIterator.hasNext() ? configSourceIterator.next().getPropertyNames().iterator() + : emptyIterator(); + } + }; } boolean negative() {