Skip to content

Commit

Permalink
Next set of small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rdebusscher committed Oct 3, 2022
1 parent 1df415b commit 78b1478
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/main/java/be/atbash/config/mp/AtbashConfigBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private Map<Type, Converter<?>> buildConverters() {
}
}

ConcurrentHashMap<Type, Converter<?>> allConverters = new ConcurrentHashMap<>(Converters.ALL_CONVERTERS);
ConcurrentHashMap<Type, Converter<?>> allConverters = new ConcurrentHashMap<>(Converters.getAllConverters());
for (Map.Entry<Type, ConverterWithPriority> entry : convertersToBuild.entrySet()) {
allConverters.put(entry.getKey(), entry.getValue().getConverter());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class AbstractDelegatingConverter<I, O> extends AbstractConverte

private final Converter<? extends I> delegate;

protected AbstractDelegatingConverter(final Converter<? extends I> delegate) {
protected AbstractDelegatingConverter(Converter<? extends I> delegate) {
this.delegate = delegate;
}

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/be/atbash/config/mp/converter/Converters.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private Converters() {
newTrimmingConverter(newEmptyValueConverter(Byte::valueOf)));

static final Converter<UUID> UUID_CONVERTER = BuiltInConverter.of(14,
newTrimmingConverter(newEmptyValueConverter((s) -> {
newTrimmingConverter(newEmptyValueConverter(s -> {
try {
return UUID.fromString(s);
} catch (IllegalArgumentException e) {
Expand All @@ -146,7 +146,7 @@ private Converters() {
newTrimmingConverter(newEmptyValueConverter(Currency::getInstance)));

static final Converter<BitSet> BITSET_CONVERTER = BuiltInConverter.of(16,
newTrimmingConverter((s) -> {
newTrimmingConverter(s -> {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
Expand All @@ -159,9 +159,13 @@ private Converters() {
static final Converter<Pattern> PATTERN_CONVERTER = BuiltInConverter.of(17,
newTrimmingConverter(newEmptyValueConverter(Pattern::compile)));

public static final Map<Class<?>, Class<?>> PRIMITIVE_TYPES;
private static final Map<Class<?>, Class<?>> PRIMITIVE_TYPES;

public static final Map<Type, Converter<?>> ALL_CONVERTERS = new HashMap<>();
private static final Map<Type, Converter<?>> ALL_CONVERTERS = new HashMap<>();

public static Map<Type, Converter<?>> getAllConverters() {
return new HashMap<>(ALL_CONVERTERS);
}

static {
ALL_CONVERTERS.put(String.class, STRING_CONVERTER);
Expand Down Expand Up @@ -355,7 +359,7 @@ public static <T> Converter<T> newTrimmingConverter(Converter<T> delegateConvert
static final class CollectionConverter<T, C extends Collection<T>> extends AbstractDelegatingConverter<T, C> {
private static final long serialVersionUID = -8452214026800305628L;

private transient final IntFunction<C> collectionFactory;
private final transient IntFunction<C> collectionFactory;

CollectionConverter(Converter<? extends T> delegate, IntFunction<C> collectionFactory) {
super(delegate);
Expand Down Expand Up @@ -384,7 +388,7 @@ public C convert(String str) {
static final class ArrayConverter<T, A> extends AbstractDelegatingConverter<T, A> {
private static final long serialVersionUID = 2630282286159527380L;

private transient final Class<A> arrayType;
private final transient Class<A> arrayType;

ArrayConverter(Converter<? extends T> delegate, Class<A> arrayType) {
super(delegate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static class StaticMethodConverter<T> implements Converter<T>, Serializable {
private static final long serialVersionUID = 3350265927359848883L;

private final Class<? extends T> clazz;
private transient final Method method;
private final transient Method method;

StaticMethodConverter(Class<? extends T> clazz, Method method) {
assert clazz == method.getReturnType();
Expand Down Expand Up @@ -143,9 +143,9 @@ Object readResolve() throws ObjectStreamException {
static class ConstructorConverter<T> implements Converter<T>, Serializable {


private transient final Constructor<? extends T> ctor;
private final transient Constructor<? extends T> ctor;

public ConstructorConverter(final Constructor<? extends T> ctor) {
public ConstructorConverter(Constructor<? extends T> ctor) {
this.ctor = ctor;
}

Expand Down
15 changes: 7 additions & 8 deletions src/main/java/be/atbash/config/mp/sources/ConfigSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ private List<ConfigSourceWithPriority> mapSources(List<ConfigSource> sources) {
return sourcesWithPriority;
}

private List<String> getProfiles(final List<ConfigSourceInterceptor> interceptors) {
for (final ConfigSourceInterceptor interceptor : interceptors) {
private List<String> getProfiles(List<ConfigSourceInterceptor> interceptors) {
for (ConfigSourceInterceptor interceptor : interceptors) {
if (interceptor instanceof ProfileConfigSourceInterceptor) {
return Arrays.asList(((ProfileConfigSourceInterceptor) interceptor).getProfiles());
}
Expand All @@ -252,12 +252,11 @@ private List<ConfigSourceWithPriority> mapLateSources(AtbashConfigSourceIntercep
}
lateSources.sort(Comparator.comparingInt(ConfigurableConfigSource::getOrdinal));

int countSourcesFromLocations = 0;
List<ConfigSourceWithPriority> sourcesWithPriority = new ArrayList<>();
for (ConfigurableConfigSource configurableSource : lateSources) {
final List<ConfigSource> configSources = configurableSource.getConfigSources(new ConfigSourceContext() {
@Override
public ConfigValue getValue(final String name) {
public ConfigValue getValue(String name) {
ConfigValue value = initChain.proceed(name);
return value != null ? value : ConfigValueImpl.builder().withName(name).build();
}
Expand All @@ -280,7 +279,7 @@ public List<String> getProfiles() {
return sourcesWithPriority;
}

private List<ConfigSource> getSources(final List<ConfigSourceWithPriority> sourceWithPriorities) {
private List<ConfigSource> getSources(List<ConfigSourceWithPriority> sourceWithPriorities) {
final List<ConfigSource> configSources = new ArrayList<>();
for (ConfigSourceWithPriority configSourceWithPriority : sourceWithPriorities) {
configSources.add(configSourceWithPriority.getSource());
Expand Down Expand Up @@ -332,7 +331,7 @@ ConfigSourceInterceptor getInterceptor(ConfigSourceInterceptorContext context) {
}

@Override
public int compareTo(final InterceptorWithPriority other) {
public int compareTo(InterceptorWithPriority other) {
return Integer.compare(this.priority, other.priority);
}
}
Expand All @@ -343,7 +342,7 @@ public static class ConfigSourceWithPriority implements Comparable<ConfigSourceW
private final int priority;
private final int loadPriority = loadPrioritySequence++;

ConfigSourceWithPriority(final ConfigSource source) {
ConfigSourceWithPriority(ConfigSource source) {
this.source = source;
this.priority = source.getOrdinal();
}
Expand All @@ -353,7 +352,7 @@ public ConfigSource getSource() {
}

@Override
public int compareTo(final ConfigSourceWithPriority other) {
public int compareTo(ConfigSourceWithPriority other) {
int res = Integer.compare(this.priority, other.priority);
return res != 0 ? res : Integer.compare(other.loadPriority, this.loadPriority);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Set<String> getPropertyNames() {
}

@Override
public String getValue(final String propertyName) {
public String getValue(String propertyName) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class AtbashConfigSourceInterceptorContext implements ConfigSourceInterceptorContext {
private static final long serialVersionUID = 6654406739008729337L;

private final ConfigSourceInterceptor interceptor;
private final transient ConfigSourceInterceptor interceptor;
private final ConfigSourceInterceptorContext next;

public AtbashConfigSourceInterceptorContext(ConfigSourceInterceptor interceptor, ConfigSourceInterceptorContext next) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ default Iterator<String> iterateNames(ConfigSourceInterceptorContext context) {
ConfigSourceInterceptor EMPTY = new ConfigSourceInterceptor() {

@Override
public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) {
public ConfigValue getValue(ConfigSourceInterceptorContext context, final String name) {
return null;
}

@Override
public Iterator<String> iterateNames(final ConfigSourceInterceptorContext context) {
public Iterator<String> iterateNames(ConfigSourceInterceptorContext context) {
return Collections.emptyIterator();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ConfigValue getProfileValue(ConfigSourceInterceptorContext context, Strin
}

@Override
public Iterator<String> iterateNames(final ConfigSourceInterceptorContext context) {
public Iterator<String> iterateNames(ConfigSourceInterceptorContext context) {
final Set<String> names = new HashSet<>();
final Iterator<String> namesIterator = context.iterateNames();
while (namesIterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@
* If <code>foo-bar</code> is present and <code>FOO_BAR</code> is also present, no additional property is required.
* If <code>FOO_BAR</code> is present an additional property <code>foo.bar</code> is added.
* <p/>
* Based on code fro mSmallRye Config.
* Based on code from SmallRye Config.
*/
public class PropertyNamesConfigSourceInterceptor implements ConfigSourceInterceptor {
private static final long serialVersionUID = 5263983885197566053L;

private final Set<String> dottedProperties = new HashSet<>();

Expand Down Expand Up @@ -76,12 +75,12 @@ public PropertyNamesConfigSourceInterceptor(Set<String> properties, List<ConfigS
}

@Override
public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) {
public ConfigValue getValue(ConfigSourceInterceptorContext context, final String name) {
return context.proceed(name);
}

@Override
public Iterator<String> iterateNames(final ConfigSourceInterceptorContext context) {
public Iterator<String> iterateNames(ConfigSourceInterceptorContext context) {
Set<String> names = new HashSet<>();
Iterator<String> namesIterator = context.iterateNames();
while (namesIterator.hasNext()) {
Expand Down
Loading

0 comments on commit 78b1478

Please sign in to comment.