Repository: incubator-tamaya Updated Branches: refs/heads/configjsr 094720846 -> f0b875d6a
- Adapted OSGI deps. - Defined clear resolvability of packages, removing redundancies. - Refactored parts of TypeLiteral into util class. Signed-off-by: Anatole Tresch <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/f0b875d6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/f0b875d6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/f0b875d6 Branch: refs/heads/configjsr Commit: f0b875d6a0ca35f0a57a043e35c4e9437f6eb9c6 Parents: 0947208 Author: Anatole Tresch <[email protected]> Authored: Mon Feb 5 19:48:26 2018 +0100 Committer: Anatole Tresch <[email protected]> Committed: Mon Feb 5 19:48:26 2018 +0100 ---------------------------------------------------------------------- .../org/apache/tamaya/base/DefaultConfig.java | 12 ++-- .../tamaya/base/DefaultServiceContext.java | 2 +- .../java/org/apache/tamaya/base/TypeUtils.java | 2 +- .../configsource/BuildableConfigSource.java | 8 +-- .../base/configsource/ConfigSourceManager.java | 6 +- .../JavaConfigurationConfigSource.java | 13 ++-- .../tamaya/base/convert/ConverterManager.java | 74 ++++++++------------ .../tamaya/base/filter/FilterManager.java | 2 +- .../spi/PropertyValueCombinationPolicy.java | 10 +-- .../java/org/apache/tamaya/spi/TypeLiteral.java | 2 +- .../tamaya/spisupport/DefaultConfiguration.java | 3 +- .../spisupport/DefaultConfigurationBuilder.java | 1 - .../spisupport/DefaultConfigurationContext.java | 12 ++-- .../DefaultConfigurationContextBuilder.java | 29 ++------ .../spisupport/PropertyConverterManager.java | 74 ++++++++------------ .../JavaConfigurationPropertySource.java | 13 ++-- .../tamaya/core/OSGIServiceComparator.java | 11 +-- .../apache/tamaya/core/OSGIServiceContext.java | 4 +- .../apache/tamaya/core/OSGIServiceLoader.java | 8 +-- .../apache/tamaya/examples/minimal/Main.java | 3 - 20 files changed, 105 insertions(+), 184 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/base/src/main/java/org/apache/tamaya/base/DefaultConfig.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/base/DefaultConfig.java b/code/base/src/main/java/org/apache/tamaya/base/DefaultConfig.java index 2549474..4a3e6c6 100644 --- a/code/base/src/main/java/org/apache/tamaya/base/DefaultConfig.java +++ b/code/base/src/main/java/org/apache/tamaya/base/DefaultConfig.java @@ -152,12 +152,12 @@ public class DefaultConfig implements Config, ConfigContextSupplier { @Override public String toString() { - StringBuilder b = new StringBuilder("Configuration{\n") - .append(this.configSourceManager).append('\n') - .append(this.filterManager).append('\n') - .append(this.converterManager).append('\n') - .append('}'); - return b.toString(); + String b = "Configuration{\n" + + this.configSourceManager + '\n' + + this.filterManager + '\n' + + this.converterManager + '\n' + + '}'; + return b; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/base/src/main/java/org/apache/tamaya/base/DefaultServiceContext.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/base/DefaultServiceContext.java b/code/base/src/main/java/org/apache/tamaya/base/DefaultServiceContext.java index 1411257..d556e3b 100644 --- a/code/base/src/main/java/org/apache/tamaya/base/DefaultServiceContext.java +++ b/code/base/src/main/java/org/apache/tamaya/base/DefaultServiceContext.java @@ -122,7 +122,7 @@ public final class DefaultServiceContext implements ServiceContext { services.add(t); } } - Collections.sort(services, org.apache.tamaya.base.PriorityServiceComparator.getInstance()); + services.sort(PriorityServiceComparator.getInstance()); services = Collections.unmodifiableList(services); } catch (ServiceConfigurationError e) { LOG.log(Level.WARNING, http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/base/src/main/java/org/apache/tamaya/base/TypeUtils.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/base/TypeUtils.java b/code/base/src/main/java/org/apache/tamaya/base/TypeUtils.java index f07d8a4..8dc3542 100644 --- a/code/base/src/main/java/org/apache/tamaya/base/TypeUtils.java +++ b/code/base/src/main/java/org/apache/tamaya/base/TypeUtils.java @@ -99,7 +99,7 @@ public final class TypeUtils { * * @return the actual type represented by defined class, or an empty array. */ - public static final Type[] getActualTypeArguments(Type type) { + public static Type[] getActualTypeArguments(Type type) { if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) type; return pt.getActualTypeArguments(); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/base/src/main/java/org/apache/tamaya/base/configsource/BuildableConfigSource.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/base/configsource/BuildableConfigSource.java b/code/base/src/main/java/org/apache/tamaya/base/configsource/BuildableConfigSource.java index b0e859b..b90453e 100644 --- a/code/base/src/main/java/org/apache/tamaya/base/configsource/BuildableConfigSource.java +++ b/code/base/src/main/java/org/apache/tamaya/base/configsource/BuildableConfigSource.java @@ -164,9 +164,7 @@ public class BuildableConfigSource implements ConfigSource{ * @return the builder */ public Builder withProperty(Map<String, String> properties, String source) { - properties.forEach((k,v) -> { - withProperty(k, v, source); - }); + properties.forEach((k,v) -> withProperty(k, v, source)); return this; } @@ -177,9 +175,7 @@ public class BuildableConfigSource implements ConfigSource{ * @return the builder */ public Builder withProperties(Map<String, String> properties) { - properties.forEach((k,v) -> { - withProperty(k, v); - }); + properties.forEach(this::withProperty); return this; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/base/src/main/java/org/apache/tamaya/base/configsource/ConfigSourceManager.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/base/configsource/ConfigSourceManager.java b/code/base/src/main/java/org/apache/tamaya/base/configsource/ConfigSourceManager.java index 09f6b5b..584b588 100644 --- a/code/base/src/main/java/org/apache/tamaya/base/configsource/ConfigSourceManager.java +++ b/code/base/src/main/java/org/apache/tamaya/base/configsource/ConfigSourceManager.java @@ -126,7 +126,7 @@ public class ConfigSourceManager { ServiceContextManager.getServiceContext().getServices(ConfigSourceProvider.class)){ provider.getConfigSources(classloader).forEach(propertySources::add); } - Collections.sort(propertySources, ConfigSourceComparator.getInstance()); + propertySources.sort(ConfigSourceComparator.getInstance()); return addSources(propertySources); } @@ -281,7 +281,7 @@ public class ConfigSourceManager { } public ConfigSourceManager sortSources(Comparator<ConfigSource> comparator) { - Collections.sort(configSources, comparator); + configSources.sort(comparator); return this; } @@ -367,7 +367,7 @@ public class ConfigSourceManager { b.append("\n"); } b.append("\n"); - b.append(" ConfigValueCombinationPolicy: " + configValueCombinationPolicy.getClass().getName()).append('\n'); + b.append(" ConfigValueCombinationPolicy: ").append(configValueCombinationPolicy.getClass().getName()).append('\n'); return b.toString(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/base/src/main/java/org/apache/tamaya/base/configsource/JavaConfigurationConfigSource.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/base/configsource/JavaConfigurationConfigSource.java b/code/base/src/main/java/org/apache/tamaya/base/configsource/JavaConfigurationConfigSource.java index 46c254d..30216a2 100644 --- a/code/base/src/main/java/org/apache/tamaya/base/configsource/JavaConfigurationConfigSource.java +++ b/code/base/src/main/java/org/apache/tamaya/base/configsource/JavaConfigurationConfigSource.java @@ -56,26 +56,23 @@ public class JavaConfigurationConfigSource extends BaseConfigSource { private boolean evaluateEnabled() { String value = System.getProperty("tamaya.defaultprops.disable"); - if(value==null){ + if (value == null) { value = System.getenv("tamaya.defaultprops.disable"); } - if(value==null){ + if (value == null) { value = System.getProperty("tamaya.defaults.disable"); } - if(value==null){ + if (value == null) { value = System.getenv("tamaya.defaults.disable"); } - if(value==null){ - return true; - } - return value.isEmpty() || !Boolean.parseBoolean(value); + return value == null || value.isEmpty() || !Boolean.parseBoolean(value); } private List<ConfigSource> getPropertySources() { List<ConfigSource> propertySources = new ArrayList<>(); propertySources.addAll(loadPropertySourcesByName(DEFAULT_SIMPLE_PROPERTIES_FILE_NAME)); propertySources.addAll(loadPropertySourcesByName(DEFAULT_XML_PROPERTIES_FILE_NAME)); - Collections.sort(propertySources, ConfigSourceComparator.getInstance()); + propertySources.sort(ConfigSourceComparator.getInstance()); return propertySources; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/base/src/main/java/org/apache/tamaya/base/convert/ConverterManager.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/base/convert/ConverterManager.java b/code/base/src/main/java/org/apache/tamaya/base/convert/ConverterManager.java index e8b28d5..1d69a48 100644 --- a/code/base/src/main/java/org/apache/tamaya/base/convert/ConverterManager.java +++ b/code/base/src/main/java/org/apache/tamaya/base/convert/ConverterManager.java @@ -55,18 +55,14 @@ public class ConverterManager { private ClassLoader classloader = ServiceContext.defaultClassLoader(); - private static final Comparator<Object> PRIORITY_COMPARATOR = new Comparator<Object>() { - - @Override - public int compare(Object o1, Object o2) { - int prio = PriorityServiceComparator.getPriority(o1) - PriorityServiceComparator.getPriority(o2); - if (prio < 0) { - return 1; - } else if (prio > 0) { - return -1; - } else { - return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName()); - } + private static final Comparator<Object> PRIORITY_COMPARATOR = (o1, o2) -> { + int prio = PriorityServiceComparator.getPriority(o1) - PriorityServiceComparator.getPriority(o2); + if (prio < 0) { + return 1; + } else if (prio > 0) { + return -1; + } else { + return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName()); } }; @@ -161,7 +157,7 @@ public class ConverterManager { converterList.add(converter); } } - Collections.sort(converterList, PRIORITY_COMPARATOR); + converterList.sort(PRIORITY_COMPARATOR); this.converters.put(typeToConvert, Collections.unmodifiableList(converterList)); addTransitiveConverters(typeToConvert, Collection.class.cast(converters)); return this; @@ -184,7 +180,7 @@ public class ConverterManager { converterList.add(converter); } } - Collections.sort(converterList, PRIORITY_COMPARATOR); + converterList.sort(PRIORITY_COMPARATOR); this.transitiveConverters.put(ifaceType, Collections.unmodifiableList(converterList)); } Class<?> superClass = targetClass.getSuperclass(); @@ -200,7 +196,7 @@ public class ConverterManager { converterList.add(converter); } } - Collections.sort(converterList, PRIORITY_COMPARATOR); + converterList.sort(PRIORITY_COMPARATOR); this.transitiveConverters.put(superClass, Collections.unmodifiableList(converterList)); addTransitiveConverters(superClass, converters); superClass = superClass.getSuperclass(); @@ -286,7 +282,7 @@ public class ConverterManager { converterList = new ArrayList<>(converterList); converterList.removeAll(converters); } - Collections.sort(converterList, PRIORITY_COMPARATOR); + converterList.sort(PRIORITY_COMPARATOR); this.converters.put(typeToConvert, Collections.unmodifiableList(converterList)); return this; } @@ -491,30 +487,21 @@ public class ConverterManager { LOG.log(Level.FINEST, "No matching constrctor for " + targetType, e); return null; } - converter = new Converter() { - @Override - public Object convert(String value) { - AccessController.doPrivileged(new PrivilegedAction<Object>() { - @Override - public Object run() { - AccessController.doPrivileged(new PrivilegedAction<Object>() { - @Override - public Object run() { - constr.setAccessible(true); - return null; - } - }); - return null; - } - }); - try { - return constr.newInstance(value); - } catch (Exception e) { - LOG.log(Level.SEVERE, "Error creating new PropertyConverter instance " + targetType, e); - } + converter = value -> { + AccessController.doPrivileged((PrivilegedAction<Object>) () -> { + AccessController.doPrivileged((PrivilegedAction<Object>) () -> { + constr.setAccessible(true); return null; - } - }; + }); + return null; + }); + try { + return constr.newInstance(value); + } catch (Exception e) { + LOG.log(Level.SEVERE, "Error creating new PropertyConverter instance " + targetType, e); + } + return null; + }; } return converter; } @@ -610,12 +597,9 @@ public class ConverterManager { "methods can be used as factory methods."); } try { - AccessController.doPrivileged(new PrivilegedAction<Object>() { - @Override - public Object run() { - factoryMethod.setAccessible(true); - return null; - } + AccessController.doPrivileged((PrivilegedAction<Object>) () -> { + factoryMethod.setAccessible(true); + return null; }); Object invoke = factoryMethod.invoke(null, value); return targetType.cast(invoke); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/base/src/main/java/org/apache/tamaya/base/filter/FilterManager.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/base/filter/FilterManager.java b/code/base/src/main/java/org/apache/tamaya/base/filter/FilterManager.java index ab52b59..6c9b51a 100644 --- a/code/base/src/main/java/org/apache/tamaya/base/filter/FilterManager.java +++ b/code/base/src/main/java/org/apache/tamaya/base/filter/FilterManager.java @@ -155,7 +155,7 @@ public class FilterManager { } public FilterManager sortFilter(Comparator<Filter> comparator) { - Collections.sort(filters, comparator); + filters.sort(comparator); return this; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/compat/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java ---------------------------------------------------------------------- diff --git a/code/compat/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java b/code/compat/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java index 14640e6..108149e 100644 --- a/code/compat/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java +++ b/code/compat/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java @@ -32,13 +32,9 @@ public interface PropertyValueCombinationPolicy { * Default overriding collector, where each existing entry ({@code current} is overridden by a subsequent non-null * entry evaluated by {@code propertySource.get(key)}. */ - PropertyValueCombinationPolicy DEFAULT_OVERRIDING_POLICY = new PropertyValueCombinationPolicy(){ - - @Override - public PropertyValue collect(PropertyValue currentValue, String key, PropertySource propertySource) { - PropertyValue value = propertySource.get(key); - return value!=null?value:currentValue; - } + PropertyValueCombinationPolicy DEFAULT_OVERRIDING_POLICY = (currentValue, key, propertySource) -> { + PropertyValue value = propertySource.get(key); + return value!=null?value:currentValue; }; /** http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/compat/src/main/java/org/apache/tamaya/spi/TypeLiteral.java ---------------------------------------------------------------------- diff --git a/code/compat/src/main/java/org/apache/tamaya/spi/TypeLiteral.java b/code/compat/src/main/java/org/apache/tamaya/spi/TypeLiteral.java index 9240602..489b467 100644 --- a/code/compat/src/main/java/org/apache/tamaya/spi/TypeLiteral.java +++ b/code/compat/src/main/java/org/apache/tamaya/spi/TypeLiteral.java @@ -72,7 +72,7 @@ public class TypeLiteral<T> implements Serializable { public static <R> TypeLiteral<R> of(Type type) { Objects.requireNonNull(type, "Type must be given."); - return new TypeLiteral<R>(type); + return new TypeLiteral<>(type); } /** http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java ---------------------------------------------------------------------- diff --git a/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java b/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java index 7a4d72b..b4b2a93 100644 --- a/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java +++ b/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java @@ -261,8 +261,7 @@ public class DefaultConfiguration implements Configuration { DefaultConfiguration that = (DefaultConfiguration) o; - if (!configurationContext.equals(that.configurationContext)) return false; - return configEvaluator.getClass().equals(that.configEvaluator.getClass()); + return configurationContext.equals(that.configurationContext) && configEvaluator.getClass().equals(that.configEvaluator.getClass()); } @Override http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java ---------------------------------------------------------------------- diff --git a/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java b/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java index 2089eb9..1b3f1ce 100644 --- a/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java +++ b/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java @@ -19,7 +19,6 @@ package org.apache.tamaya.spisupport; import org.apache.tamaya.Configuration; -import org.apache.tamaya.spi.TypeLiteral; import org.apache.tamaya.spi.*; import org.apache.tamaya.spi.ConfigurationBuilder; http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java ---------------------------------------------------------------------- diff --git a/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java b/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java index 1717203..ecb8894 100644 --- a/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java +++ b/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java @@ -19,7 +19,6 @@ package org.apache.tamaya.spisupport; import org.apache.tamaya.base.ServiceContextManager; -import org.apache.tamaya.spi.TypeLiteral; import org.apache.tamaya.spi.*; import java.util.*; @@ -101,7 +100,7 @@ public class DefaultConfigurationContext implements ConfigurationContext { writeLock.lock(); List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources); newPropertySources.addAll(Arrays.asList(propertySourcesToAdd)); - Collections.sort(newPropertySources, PropertySourceComparator.getInstance()); + newPropertySources.sort(PropertySourceComparator.getInstance()); this.immutablePropertySources = Collections.unmodifiableList(newPropertySources); } finally { @@ -114,7 +113,7 @@ public class DefaultConfigurationContext implements ConfigurationContext { if (this == o) { return true; } - if (!(o instanceof DefaultConfigurationContext)){ + if (!(o instanceof DefaultConfigurationContext)) { return false; } @@ -126,10 +125,7 @@ public class DefaultConfigurationContext implements ConfigurationContext { if (!immutablePropertySources.equals(that.immutablePropertySources)) { return false; } - if (!immutablePropertyFilters.equals(that.immutablePropertyFilters)) { - return false; - } - return getPropertyValueCombinationPolicy().equals(that.getPropertyValueCombinationPolicy()); + return immutablePropertyFilters.equals(that.immutablePropertyFilters) && getPropertyValueCombinationPolicy().equals(that.getPropertyValueCombinationPolicy()); } @@ -205,7 +201,7 @@ public class DefaultConfigurationContext implements ConfigurationContext { } } b.append("\n\n"); - b.append(" PropertyValueCombinationPolicy: " + getPropertyValueCombinationPolicy().getClass().getName()).append('\n'); + b.append(" PropertyValueCombinationPolicy: ").append(getPropertyValueCombinationPolicy().getClass().getName()).append('\n'); b.append('}'); return b.toString(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java ---------------------------------------------------------------------- diff --git a/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java b/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java index 200556f..461261c 100644 --- a/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java +++ b/code/compat/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java @@ -19,7 +19,6 @@ package org.apache.tamaya.spisupport; import org.apache.tamaya.base.ServiceContextManager; -import org.apache.tamaya.spi.TypeLiteral; import org.apache.tamaya.spi.*; import org.apache.tamaya.spisupport.propertysource.CLIPropertySource; import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource; @@ -93,9 +92,7 @@ public class DefaultConfigurationContextBuilder implements ConfigurationContextB public ConfigurationContextBuilder setContext(ConfigurationContext context) { checkBuilderState(); this.propertyConverters.putAll(context.getPropertyConverters()); - for(PropertySource ps:context.getPropertySources()){ - this.propertySources.add(ps); - } + this.propertySources.addAll(context.getPropertySources()); this.propertyFilters.addAll(context.getPropertyFilters()); this.combinationPolicy = context.getPropertyValueCombinationPolicy(); return this; @@ -131,7 +128,7 @@ public class DefaultConfigurationContextBuilder implements ConfigurationContextB ServiceContextManager.getServiceContext().getServices(PropertySourceProvider.class)){ propertySources.addAll(provider.getPropertySources()); } - Collections.sort(propertySources, PropertySourceComparator.getInstance()); + propertySources.sort(PropertySourceComparator.getInstance()); return addPropertySources(propertySources); } @@ -321,11 +318,7 @@ public class DefaultConfigurationContextBuilder implements ConfigurationContextB checkBuilderState(); Objects.requireNonNull(type); Objects.requireNonNull(propertyConverters); - Collection<PropertyConverter<?>> converters = this.propertyConverters.get(type); - if(converters==null){ - converters = new ArrayList<>(); - this.propertyConverters.put(type, converters); - } + Collection<PropertyConverter<?>> converters = this.propertyConverters.computeIfAbsent(type, k -> new ArrayList<>()); for(PropertyConverter<T> propertyConverter:propertyConverters) { if (!converters.contains(propertyConverter)) { converters.add(propertyConverter); @@ -341,11 +334,7 @@ public class DefaultConfigurationContextBuilder implements ConfigurationContextB checkBuilderState(); Objects.requireNonNull(type); Objects.requireNonNull(propertyConverters); - Collection<PropertyConverter<?>> converters = this.propertyConverters.get(type); - if(converters==null){ - converters = new ArrayList<>(); - this.propertyConverters.put(type, converters); - } + Collection<PropertyConverter<?>> converters = this.propertyConverters.computeIfAbsent(type, k -> new ArrayList<>()); for(PropertyConverter<T> propertyConverter:propertyConverters) { if (!converters.contains(propertyConverter)) { converters.add(propertyConverter); @@ -375,11 +364,7 @@ public class DefaultConfigurationContextBuilder implements ConfigurationContextB ParameterizedType pt = (ParameterizedType)type; if(PropertyConverter.class.equals(((ParameterizedType) type).getRawType())){ TypeLiteral target = TypeLiteral.of(pt.getActualTypeArguments()[0]); - Collection<PropertyConverter> convList = result.get(target); - if (convList == null) { - convList = new ArrayList<>(); - result.put(target, convList); - } + Collection<PropertyConverter> convList = result.computeIfAbsent(target, k -> new ArrayList<>()); convList.add(conv); } } @@ -404,13 +389,13 @@ public class DefaultConfigurationContextBuilder implements ConfigurationContextB @Override public ConfigurationContextBuilder sortPropertyFilter(Comparator<PropertyFilter> comparator) { - Collections.sort(propertyFilters, comparator); + propertyFilters.sort(comparator); return this; } @Override public ConfigurationContextBuilder sortPropertySources(Comparator<PropertySource> comparator) { - Collections.sort(propertySources, comparator); + propertySources.sort(comparator); return this; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/compat/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java ---------------------------------------------------------------------- diff --git a/code/compat/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java b/code/compat/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java index bc1f30d..bd62e2b 100644 --- a/code/compat/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java +++ b/code/compat/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java @@ -61,18 +61,14 @@ public class PropertyConverterManager { */ private final ReadWriteLock lock = new ReentrantReadWriteLock(); - private static final Comparator<Object> PRIORITY_COMPARATOR = new Comparator<Object>() { - - @Override - public int compare(Object o1, Object o2) { - int prio = org.apache.tamaya.base.PriorityServiceComparator.getPriority(o1) - PriorityServiceComparator.getPriority(o2); - if (prio < 0) { - return 1; - } else if (prio > 0) { - return -1; - } else { - return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName()); - } + private static final Comparator<Object> PRIORITY_COMPARATOR = (o1, o2) -> { + int prio = PriorityServiceComparator.getPriority(o1) - PriorityServiceComparator.getPriority(o2); + if (prio < 0) { + return 1; + } else if (prio > 0) { + return -1; + } else { + return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName()); } }; @@ -124,7 +120,7 @@ public class PropertyConverterManager { if(!newConverters.contains(converter)) { newConverters.add(converter); } - Collections.sort(newConverters, PRIORITY_COMPARATOR); + newConverters.sort(PRIORITY_COMPARATOR); this.converters.put(targetType, Collections.unmodifiableList(newConverters)); // evaluate transitive closure for all inherited supertypes and implemented interfaces // direct implemented interfaces @@ -135,7 +131,7 @@ public class PropertyConverterManager { newConverters.addAll(converters); } newConverters.add(converter); - Collections.sort(newConverters, PRIORITY_COMPARATOR); + newConverters.sort(PRIORITY_COMPARATOR); this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters)); } Class<?> superClass = targetType.getRawType().getSuperclass(); @@ -146,7 +142,7 @@ public class PropertyConverterManager { newConverters.addAll(converters); } newConverters.add(converter); - Collections.sort(newConverters, PRIORITY_COMPARATOR); + newConverters.sort(PRIORITY_COMPARATOR); this.transitiveConverters.put(TypeLiteral.of(superClass), Collections.unmodifiableList(newConverters)); for (Class<?> ifaceType : superClass.getInterfaces()) { converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType))); @@ -155,7 +151,7 @@ public class PropertyConverterManager { newConverters.addAll(converters); } newConverters.add(converter); - Collections.sort(newConverters, PRIORITY_COMPARATOR); + newConverters.sort(PRIORITY_COMPARATOR); this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters)); } superClass = superClass.getSuperclass(); @@ -364,30 +360,21 @@ public class PropertyConverterManager { LOG.log(Level.FINEST, "No matching constrctor for " + targetType, e); return null; } - converter = new PropertyConverter<T>() { - @Override - public T convert(String value, ConversionContext context) { - AccessController.doPrivileged(new PrivilegedAction<Object>() { - @Override - public Object run() { - AccessController.doPrivileged(new PrivilegedAction<Object>() { - @Override - public Object run() { - constr.setAccessible(true); - return null; - } - }); - return null; - } - }); - try { - return constr.newInstance(value); - } catch (Exception e) { - LOG.log(Level.SEVERE, "Error creating new PropertyConverter instance " + targetType, e); - } + converter = (value, context) -> { + AccessController.doPrivileged((PrivilegedAction<Object>) () -> { + AccessController.doPrivileged((PrivilegedAction<Object>) () -> { + constr.setAccessible(true); return null; - } - }; + }); + return null; + }); + try { + return constr.newInstance(value); + } catch (Exception e) { + LOG.log(Level.SEVERE, "Error creating new PropertyConverter instance " + targetType, e); + } + return null; + }; } return converter; } @@ -455,12 +442,9 @@ public class PropertyConverterManager { "methods can be used as factory methods."); } try { - AccessController.doPrivileged(new PrivilegedAction<Object>() { - @Override - public Object run() { - factoryMethod.setAccessible(true); - return null; - } + AccessController.doPrivileged((PrivilegedAction<Object>) () -> { + factoryMethod.setAccessible(true); + return null; }); Object invoke = factoryMethod.invoke(null, value); return targetType.cast(invoke); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/compat/src/main/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationPropertySource.java ---------------------------------------------------------------------- diff --git a/code/compat/src/main/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationPropertySource.java b/code/compat/src/main/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationPropertySource.java index 7f64810..f19f185 100644 --- a/code/compat/src/main/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationPropertySource.java +++ b/code/compat/src/main/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationPropertySource.java @@ -59,26 +59,23 @@ public class JavaConfigurationPropertySource extends BasePropertySource { private boolean evaluateEnabled() { String value = System.getProperty("tamaya.defaultprops.disable"); - if(value==null){ + if (value == null) { value = System.getenv("tamaya.defaultprops.disable"); } - if(value==null){ + if (value == null) { value = System.getProperty("tamaya.defaults.disable"); } - if(value==null){ + if (value == null) { value = System.getenv("tamaya.defaults.disable"); } - if(value==null){ - return true; - } - return value.isEmpty() || !Boolean.parseBoolean(value); + return value == null || value.isEmpty() || !Boolean.parseBoolean(value); } private List<PropertySource> getPropertySources() { List<PropertySource> propertySources = new ArrayList<>(); propertySources.addAll(loadPropertySourcesByName(DEFAULT_SIMPLE_PROPERTIES_FILE_NAME)); propertySources.addAll(loadPropertySourcesByName(DEFAULT_XML_PROPERTIES_FILE_NAME)); - Collections.sort(propertySources, PropertySourceComparator.getInstance()); + propertySources.sort(PropertySourceComparator.getInstance()); return propertySources; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceComparator.java ---------------------------------------------------------------------- diff --git a/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceComparator.java b/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceComparator.java index 009927d..25c3b91 100644 --- a/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceComparator.java +++ b/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceComparator.java @@ -32,13 +32,8 @@ class OSGIServiceComparator implements Comparator<ServiceReference> { @Override public int compare(ServiceReference o1, ServiceReference o2) { int prio = getPriority(o1) - getPriority(o2); - if (prio < 0) { - return 1; - } else if (prio > 0) { - return -1; - } else { - return 0; //o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName()); - } + //o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName()); + return Integer.compare(0, prio); } /** @@ -59,7 +54,7 @@ class OSGIServiceComparator implements Comparator<ServiceReference> { * @param type the type, not {@code null}. * @return a priority, by default 1. */ - public static int getPriority(Class<? extends Object> type) { + public static int getPriority(Class<?> type) { int prio = 1; Priority priority = type.getAnnotation(Priority.class); if (priority != null) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceContext.java ---------------------------------------------------------------------- diff --git a/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceContext.java b/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceContext.java index 8359fb9..e674003 100644 --- a/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceContext.java +++ b/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceContext.java @@ -66,7 +66,7 @@ public class OSGIServiceContext implements ServiceContext{ this.osgiServiceLoader.getBundleContext().registerService( serviceType.getName(), service, - new Hashtable<String, Object>()); + new Hashtable<>()); return service; } return null; @@ -104,7 +104,7 @@ public class OSGIServiceContext implements ServiceContext{ List<T> services = new ArrayList<>(refs.size()); try { refs.addAll(this.osgiServiceLoader.getBundleContext().getServiceReferences(serviceType, null)); - Collections.sort(refs, REF_COMPARATOR); + refs.sort(REF_COMPARATOR); for(ServiceReference<T> ref:refs){ T service = osgiServiceLoader.getBundleContext().getService(ref); if(service!=null) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceLoader.java ---------------------------------------------------------------------- diff --git a/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceLoader.java b/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceLoader.java index 96e3da9..0546cdf 100644 --- a/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceLoader.java +++ b/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceLoader.java @@ -158,10 +158,8 @@ public class OSGIServiceLoader implements BundleListener { BundleContext bundleContext = bundle.getBundleContext(); bundleContext.registerService(serviceName, factory, props); log.info("Registered Tamaya service class: " + implClassName + "(" + serviceName + ")"); - } catch (Exception e) { + } catch (Exception | NoClassDefFoundError e) { log.log(Level.SEVERE, "Failed to load service: " + implClassName, e); - } catch (NoClassDefFoundError err) { - log.log(Level.SEVERE, "Failed to load service: " + implClassName, err); } } implClassName = br.readLine(); @@ -210,10 +208,8 @@ public class OSGIServiceLoader implements BundleListener { if (ref != null) { bundle.getBundleContext().ungetService(ref); } - } catch (Exception e) { + } catch (Exception | NoClassDefFoundError e) { log.log(Level.SEVERE, "Failed to unload service: " + implClassName, e); - } catch (NoClassDefFoundError err) { - log.log(Level.SEVERE, "Failed to unload service: " + implClassName, err); } } implClassName = br.readLine(); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f0b875d6/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java ---------------------------------------------------------------------- diff --git a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java index 93db446..98cb954 100644 --- a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java +++ b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java @@ -21,9 +21,6 @@ package org.apache.tamaya.examples.minimal; import javax.config.Config; import javax.config.ConfigProvider; import java.io.PrintStream; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; import java.util.logging.LogManager; import java.util.logging.Logger;
