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

Use Map.forEach for iterating over values #1280

Merged
merged 1 commit into from
Jan 5, 2025
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 @@ -29,6 +29,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

import io.smallrye.config.common.AbstractConfigSource;

Expand Down Expand Up @@ -78,14 +79,16 @@ public EnvConfigSource(final Map<String, String> properties, final int ordinal)
@Override
public Map<String, String> getProperties() {
Map<String, String> properties = new HashMap<>();
for (Map.Entry<EnvName, EnvEntry> entry : envVars.getEnv().entrySet()) {
EnvEntry entryValue = entry.getValue();
if (entryValue.getEntries() != null) {
properties.putAll(entryValue.getEntries());
} else {
properties.put(entryValue.getName(), entryValue.getValue());
envVars.getEnv().forEach(new BiConsumer<>() {
@Override
public void accept(EnvName key, EnvEntry entryValue) {
if (entryValue.getEntries() != null) {
properties.putAll(entryValue.getEntries());
} else {
properties.put(entryValue.getName(), entryValue.getValue());
}
}
}
});
return properties;
}

Expand Down Expand Up @@ -149,17 +152,20 @@ static final class EnvVars implements Serializable {
public EnvVars(final Map<String, String> properties) {
this.env = new HashMap<>(properties.size());
this.names = new HashSet<>(properties.size() * 2);
for (Map.Entry<String, String> entry : properties.entrySet()) {
EnvName envName = new EnvName(entry.getKey());
EnvEntry envEntry = env.get(envName);
if (envEntry == null) {
env.put(envName, new EnvEntry(entry.getKey(), entry.getValue()));
} else {
envEntry.add(entry.getKey(), entry.getValue());
properties.forEach(new BiConsumer<>() {
@Override
public void accept(String key, String value) {
EnvName envName = new EnvName(key);
EnvEntry envEntry = env.get(envName);
if (envEntry == null) {
env.put(envName, new EnvEntry(key, value));
} else {
envEntry.add(key, value);
}
EnvVars.this.names.add(key);
EnvVars.this.names.add(toLowerCaseAndDotted(key));
}
this.names.add(entry.getKey());
this.names.add(toLowerCaseAndDotted(entry.getKey()));
}
});
}

public String get(final String propertyName) {
Expand Down
Loading