39public final class EtherConfig {
41 private final List<ConfigSource> sources;
43 private EtherConfig(
final List<ConfigSource> sources) {
44 this.sources = List.copyOf(sources);
48 return of(List.of(sources));
51 public static EtherConfig
of(
final List<ConfigSource> sources) {
52 Objects.requireNonNull(sources,
"sources");
53 return new EtherConfig(
new ArrayList<>(sources));
60 public Optional<String>
get(
final String key) {
61 for (
final var source : sources) {
62 final var value = source.get(key);
63 if (value.isPresent()) {
67 return Optional.empty();
71 return get(key).orElseThrow(() ->
new IllegalArgumentException(
"Missing config key: " + key));
75 final var merged =
new LinkedHashMap<String, String>();
76 for (
final var source : sources) {
77 for (
final var entry : source.entries().entrySet()) {
78 merged.putIfAbsent(entry.getKey(), entry.getValue());
81 return Map.copyOf(merged);
84 public <T extends Record> T bind(
final Class<T> recordType) {
88 public <T extends Record> T bind(
final String prefix,
final Class<T> recordType) {
89 return ConfigBinder.bind(
this, prefix, recordType);
92 public <T extends Record> T bindValidated(
final Class<T> recordType) {
93 return ConfigBinder.bindValidated(
this, recordType);
96 public <T extends Record> T bindValidated(
final String prefix,
final Class<T> recordType) {
97 return ConfigBinder.bindValidated(
this, prefix, recordType);