This is an automated email from the ASF dual-hosted git repository. anatole pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tamaya-sandbox.git
commit 1f9f59a92444a110bf57281006d7de00c69b48b4 Author: Anatole Tresch <[email protected]> AuthorDate: Sun Mar 3 23:14:17 2019 +0100 Adapted to latest API changes. --- .../apache/tamaya/jsr382/TamayaConfigAccessor.java | 203 ++++++++------------- 1 file changed, 75 insertions(+), 128 deletions(-) diff --git a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaConfigAccessor.java b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaConfigAccessor.java index 616c04e..a0625ce 100644 --- a/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaConfigAccessor.java +++ b/configjsr/src/main/java/org/apache/tamaya/jsr382/TamayaConfigAccessor.java @@ -59,8 +59,11 @@ class TamayaConfigAccessor<T> implements ConfigAccessor<T> { this.javaConfigAdapter = builder.configAdapter; this.evaluateVariables = builder.evaluateVariables; this.lookupSuffixes.addAll(builder.lookupSuffixes); + this.customConverter = builder.customConverter; + this.typedDefaultValue = builder.typedDefaultValue; // What to do if the fallback accessors do not match, e.g. with collection types... this.fallbackAccessors.addAll(builder.fallbackAccessors); + this.cachedValue = getValue(); } /** @@ -96,134 +99,6 @@ class TamayaConfigAccessor<T> implements ConfigAccessor<T> { return result; } - static final class TamayaConfigAccessorBuilder<T> implements ConfigAccessor.Builder<T>{ - - private String name; - private JavaConfigAdapter configAdapter; - private Converter<T> customConverter; - private TypeLiteral<T> targetType; - private T typedDefaultValue; - private String stringDefaultValue; - private List<ConfigAccessor<String>> fallbackAccessors = new ArrayList<>(); - private List<String> lookupSuffixes = new ArrayList<>(); - private boolean evaluateVariables = true; - private long timeout = 0; - private T cachedValue; - private Duration cacheDuration; - - /** - * Constructor. - * - * @param configAdapter the config, not null. - */ - TamayaConfigAccessorBuilder(JavaConfigAdapter configAdapter, String name, TypeLiteral<T> type) { - this.configAdapter = configAdapter; - this.name = name; - this.targetType = targetType; - } - - @Override - public Builder<T> useConverter(Converter<T> converter) { - this.customConverter = Objects.requireNonNull(converter); - return this; - } - - @Override - public Builder<T> withDefault(T value) { - this.typedDefaultValue = Objects.requireNonNull(value); - return this; - } - - @Override - public Builder<T> withStringDefault(String value) { - this.stringDefaultValue = value; - return this; - } - - @Override - public Builder<T> cacheFor(Duration duration) { - this.cacheDuration = Objects.requireNonNull(duration); - return this; - } - - @Override - public Builder<T> evaluateVariables(boolean evaluateVariables) { - this.evaluateVariables = evaluateVariables; - return this; - } - - @Override - public Builder<T> addLookupSuffix(String suffixValue) { - this.lookupSuffixes.add(Objects.requireNonNull(suffixValue)); - return this; - } - - @Override - public ConfigAccessor<T> build() { - return new TamayaConfigAccessor<T>(this); - } - } - -// @Override -// public <N> ConfigAccessor<N> as(Class<N> aClass) { -// return new TamayaConfigAccessor<N>(this, TypeLiteral.of(aClass)); -// } -// -// @Override -// public ConfigAccessor<List<T>> asList() { -// TypeLiteral<List<T>> target = new TypeLiteral<List<T>>(); -// return new TamayaConfigAccessor<List<T>>(this, target); -// } -// -// @Override -// public ConfigAccessor<Set<T>> asSet() { -// TypeLiteral<Set<T>> target = new TypeLiteral<Set<T>>(); -// return new TamayaConfigAccessor<Set<T>>(this, target); -// } -// -// @Override -// public ConfigAccessor<T> useConverter(Converter<T> converter) { -// this.customConverter = converter; -// return this; -// } -// -// @Override -// public ConfigAccessor<T> withDefault(T defaultValue) { -// this.typedDefaultValue = defaultValue; -// return this; -// } -// -// @Override -// public ConfigAccessor<T> withStringDefault(String defaultValue) { -// this.stringDefaultValue = defaultValue; -// return this; -// } -// -// @Override -// public ConfigAccessor<T> cacheFor(long duration, TimeUnit timeUnit) { -// this.cachedValue = getValue(); -// this.timeout = System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(duration, timeUnit); -// return this; -// } -// -// @Override -// public ConfigAccessor<T> evaluateVariables(boolean evaluateVariables) { -// this.evaluateVariables = evaluateVariables; -// return this; -// } -// -// @Override -// public ConfigAccessor<T> addLookupSuffix(String lookupSuffix) { -// this.lookupSuffixes.add(lookupSuffix); -// return this; -// } -// -// @Override -// public ConfigAccessor<T> addLookupSuffix(ConfigAccessor<String> configAccessor) { -// this.fallbackAccessors.add(configAccessor); -// return this; -// } - @Override public T getValue() { if (this.timeout > System.currentTimeMillis()) { @@ -319,4 +194,76 @@ class TamayaConfigAccessor<T> implements ConfigAccessor<T> { '}'; } + /** + * Implementation of the {@link javax.config.ConfigAccessor.Builder} class. + * @param <T> the type. + */ + static final class TamayaConfigAccessorBuilder<T> implements ConfigAccessor.Builder<T>{ + + private String name; + private JavaConfigAdapter configAdapter; + private Converter<T> customConverter; + private TypeLiteral<T> targetType; + private T typedDefaultValue; + private String stringDefaultValue; + private List<ConfigAccessor<String>> fallbackAccessors = new ArrayList<>(); + private List<String> lookupSuffixes = new ArrayList<>(); + private boolean evaluateVariables = true; + private long timeout = 0; + private T cachedValue; + private Duration cacheDuration; + + /** + * Constructor. + * + * @param configAdapter the config, not null. + */ + TamayaConfigAccessorBuilder(JavaConfigAdapter configAdapter, String name, TypeLiteral<T> type) { + this.configAdapter = configAdapter; + this.name = name; + this.targetType = targetType; + } + + @Override + public Builder<T> useConverter(Converter<T> converter) { + this.customConverter = Objects.requireNonNull(converter); + return this; + } + + @Override + public Builder<T> withDefault(T value) { + this.typedDefaultValue = Objects.requireNonNull(value); + return this; + } + + @Override + public Builder<T> withStringDefault(String value) { + this.stringDefaultValue = value; + return this; + } + + @Override + public Builder<T> cacheFor(Duration duration) { + this.cacheDuration = Objects.requireNonNull(duration); + return this; + } + + @Override + public Builder<T> evaluateVariables(boolean evaluateVariables) { + this.evaluateVariables = evaluateVariables; + return this; + } + + @Override + public Builder<T> addLookupSuffix(String suffixValue) { + this.lookupSuffixes.add(Objects.requireNonNull(suffixValue)); + return this; + } + + @Override + public ConfigAccessor<T> build() { + return new TamayaConfigAccessor<T>(this); + } + } + }
