Polish
This commit is contained in:
parent
461cca3269
commit
d4f87ae74e
|
@ -90,8 +90,8 @@ public class DataSourceBuilder {
|
|||
ConfigurationPropertySource source = new MapConfigurationPropertySource(
|
||||
this.properties);
|
||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||
aliases.addAlaises("url", "jdbc-url");
|
||||
aliases.addAlaises("username", "user");
|
||||
aliases.addAliases("url", "jdbc-url");
|
||||
aliases.addAliases("username", "user");
|
||||
Binder binder = new Binder(source.withAliases(aliases));
|
||||
binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(result));
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ public class XADataSourceAutoConfiguration implements BeanClassLoaderAware {
|
|||
source.put("url", this.properties.determineUrl());
|
||||
source.putAll(dataSourceProperties.getXa().getProperties());
|
||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||
aliases.addAlaises("user", "username");
|
||||
aliases.addAliases("user", "username");
|
||||
return source.withAliases(aliases);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public class ConfigurationBeanFactoryMetaData implements BeanFactoryPostProcesso
|
|||
|
||||
private ConfigurableListableBeanFactory beanFactory;
|
||||
|
||||
private Map<String, MetaData> beans = new HashMap<>();
|
||||
private final Map<String, MetaData> beans = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
|
||||
|
@ -96,9 +96,9 @@ public class ConfigurationBeanFactoryMetaData implements BeanFactoryPostProcesso
|
|||
|
||||
private static class MetaData {
|
||||
|
||||
private String bean;
|
||||
private final String bean;
|
||||
|
||||
private String method;
|
||||
private final String method;
|
||||
|
||||
MetaData(String bean, String method) {
|
||||
this.bean = bean;
|
||||
|
|
|
@ -465,7 +465,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
|
|||
*/
|
||||
private static class ChainingValidator implements Validator {
|
||||
|
||||
private Validator[] validators;
|
||||
private final Validator[] validators;
|
||||
|
||||
ChainingValidator(Validator... validators) {
|
||||
Assert.notNull(validators, "Validators must not be null");
|
||||
|
|
|
@ -29,7 +29,7 @@ interface BeanBinder {
|
|||
/**
|
||||
* Return a bound bean instance or {@code null} if the {@link BeanBinder} does not
|
||||
* support the specified {@link Bindable}.
|
||||
* @param target the binable to bind
|
||||
* @param target the bindable to bind
|
||||
* @param hasKnownBindableProperties if this binder has known bindable elements. If
|
||||
* names from underlying {@link ConfigurationPropertySource} cannot be iterated this
|
||||
* method can be {@code false}, even though binding may ultimately succeed.
|
||||
|
|
|
@ -78,7 +78,7 @@ public class BindException extends RuntimeException implements OriginProvider {
|
|||
StringBuilder message = new StringBuilder();
|
||||
message.append("Failed to bind properties");
|
||||
message.append(name == null ? "" : " under '" + name + "'");
|
||||
message.append(" to " + target.getType());
|
||||
message.append(" to ").append(target.getType());
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.springframework.boot.context.properties.source.ConfigurationPropertyN
|
|||
public interface BindHandler {
|
||||
|
||||
/**
|
||||
* Default no-op bind hander.
|
||||
* Default no-op bind handler.
|
||||
*/
|
||||
BindHandler DEFAULT = new BindHandler() {
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ public final class BindResult<T> {
|
|||
if (value == null) {
|
||||
return (BindResult<T>) UNBOUND;
|
||||
}
|
||||
return new BindResult<T>(value);
|
||||
return new BindResult<>(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ public final class Bindable<T> {
|
|||
* @return an updated {@link Bindable}
|
||||
*/
|
||||
public Bindable<T> withAnnotations(Annotation... annotations) {
|
||||
return new Bindable<T>(this.type, this.boxedType, this.value,
|
||||
return new Bindable<>(this.type, this.boxedType, this.value,
|
||||
(annotations == null ? NO_ANNOTATIONS : annotations));
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ public final class Bindable<T> {
|
|||
Class<?> wrapperType = Array.get(array, 0).getClass();
|
||||
return ResolvableType.forClass(wrapperType);
|
||||
}
|
||||
if (resolved.isArray()) {
|
||||
if (resolved != null && resolved.isArray()) {
|
||||
return ResolvableType.forArrayComponent(box(type.getComponentType()));
|
||||
}
|
||||
return type;
|
||||
|
|
|
@ -287,7 +287,7 @@ public class Binder {
|
|||
}
|
||||
|
||||
private Object bindBean(ConfigurationPropertyName name, Bindable<?> target,
|
||||
BindHandler handler, Context context) throws Exception {
|
||||
BindHandler handler, Context context) {
|
||||
boolean hasKnownBindableProperties = context.streamSources()
|
||||
.flatMap((s) -> s.filter(name::isAncestorOf).stream()).findAny()
|
||||
.isPresent();
|
||||
|
|
|
@ -44,12 +44,12 @@ class JavaBeanBinder implements BeanBinder {
|
|||
return null;
|
||||
}
|
||||
BeanSupplier<T> beanSupplier = bean.getSupplier(target);
|
||||
boolean bound = bind(target, propertyBinder, bean, beanSupplier);
|
||||
boolean bound = bind(propertyBinder, bean, beanSupplier);
|
||||
return (bound ? beanSupplier.get() : null);
|
||||
}
|
||||
|
||||
private <T> boolean bind(Bindable<T> target, BeanPropertyBinder propertyBinder,
|
||||
Bean<T> bean, BeanSupplier<T> beanSupplier) {
|
||||
private <T> boolean bind(BeanPropertyBinder propertyBinder, Bean<T> bean,
|
||||
BeanSupplier<T> beanSupplier) {
|
||||
boolean bound = false;
|
||||
for (Map.Entry<String, BeanProperty> entry : bean.getProperties().entrySet()) {
|
||||
bound |= bind(beanSupplier, propertyBinder, entry.getValue());
|
||||
|
@ -151,7 +151,7 @@ class JavaBeanBinder implements BeanBinder {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public BeanSupplier<T> getSupplier(Bindable<T> target) {
|
||||
return new BeanSupplier<T>(() -> {
|
||||
return new BeanSupplier<>(() -> {
|
||||
T instance = null;
|
||||
if (target.getValue() != null) {
|
||||
instance = target.getValue().get();
|
||||
|
@ -168,7 +168,7 @@ class JavaBeanBinder implements BeanBinder {
|
|||
boolean useExistingValueForType) {
|
||||
Class<?> type = bindable.getType().resolve();
|
||||
Supplier<T> value = bindable.getValue();
|
||||
if (value == null && !isInstantiatable(type)) {
|
||||
if (value == null && !isInstantiable(type)) {
|
||||
return null;
|
||||
}
|
||||
if (useExistingValueForType && value != null) {
|
||||
|
@ -183,7 +183,7 @@ class JavaBeanBinder implements BeanBinder {
|
|||
return (Bean<T>) bean;
|
||||
}
|
||||
|
||||
private static boolean isInstantiatable(Class<?> type) {
|
||||
private static boolean isInstantiable(Class<?> type) {
|
||||
if (type.isInterface()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
|
|||
public void bindEntries(ConfigurationPropertySource source,
|
||||
Map<Object, Object> map) {
|
||||
for (ConfigurationPropertyName name : source) {
|
||||
Bindable<?> valueBindable = getValueBindable(source, name);
|
||||
Bindable<?> valueBindable = getValueBindable(name);
|
||||
ConfigurationPropertyName entryName = getEntryName(source, name);
|
||||
Object key = getContext().getConversionService()
|
||||
.convert(getKeyName(entryName), this.keyType);
|
||||
|
@ -93,8 +93,7 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
|
|||
}
|
||||
}
|
||||
|
||||
private Bindable<?> getValueBindable(ConfigurationPropertySource source,
|
||||
ConfigurationPropertyName name) {
|
||||
private Bindable<?> getValueBindable(ConfigurationPropertyName name) {
|
||||
if (isMultiElementName(name) && isValueTreatedAsNestedMap()) {
|
||||
return Bindable.of(this.mapType);
|
||||
}
|
||||
|
|
|
@ -33,9 +33,9 @@ import org.springframework.util.SystemPropertyUtils;
|
|||
*/
|
||||
public class PropertySourcesPlaceholdersResolver implements PlaceholdersResolver {
|
||||
|
||||
private PropertySources sources;
|
||||
private final PropertySources sources;
|
||||
|
||||
private PropertyPlaceholderHelper helper;
|
||||
private final PropertyPlaceholderHelper helper;
|
||||
|
||||
public PropertySourcesPlaceholdersResolver(Environment environment) {
|
||||
this(getSources(environment), null);
|
||||
|
|
|
@ -46,7 +46,7 @@ public class ValidationBindHandler extends AbstractBindHandler {
|
|||
|
||||
private boolean validate;
|
||||
|
||||
private Set<ConfigurationProperty> boundProperties = new LinkedHashSet<>();
|
||||
private final Set<ConfigurationProperty> boundProperties = new LinkedHashSet<>();
|
||||
|
||||
public ValidationBindHandler(Validator... validators) {
|
||||
super();
|
||||
|
|
|
@ -141,7 +141,7 @@ public final class ConfigurationPropertyName
|
|||
* Returns {@code true} if this element is an ancestor (immediate or nested parent) or
|
||||
* the specified name.
|
||||
* @param name the name to check
|
||||
* @return {@code true} if this name is an ancessor
|
||||
* @return {@code true} if this name is an ancestor
|
||||
*/
|
||||
public boolean isAncestorOf(ConfigurationPropertyName name) {
|
||||
ConfigurationPropertyName candidate = (name == null ? null : name.getParent());
|
||||
|
@ -231,8 +231,8 @@ public final class ConfigurationPropertyName
|
|||
public static ConfigurationPropertyName of(String name)
|
||||
throws IllegalArgumentException {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
Assert.isTrue(!name.toString().startsWith("."), "Name must not start with '.'");
|
||||
Assert.isTrue(!name.toString().endsWith("."), "Name must not end with '.'");
|
||||
Assert.isTrue(!name.startsWith("."), "Name must not start with '.'");
|
||||
Assert.isTrue(!name.endsWith("."), "Name must not end with '.'");
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return EMPTY;
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ public final class ConfigurationPropertyName
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
String string = getValue(Form.CONFIGURATION).toString();
|
||||
String string = getValue(Form.CONFIGURATION);
|
||||
return (this.indexed ? "[" + string + "]" : string);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.springframework.util.LinkedMultiValueMap;
|
|||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* Maintains a mapping of {@link ConfigurationPropertyName} alaises.
|
||||
* Maintains a mapping of {@link ConfigurationPropertyName} aliases.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Madhura Bhave
|
||||
|
@ -41,23 +41,23 @@ public final class ConfigurationPropertyNameAliases {
|
|||
}
|
||||
|
||||
public ConfigurationPropertyNameAliases(String name, String... aliases) {
|
||||
addAlaises(name, aliases);
|
||||
addAliases(name, aliases);
|
||||
}
|
||||
|
||||
public ConfigurationPropertyNameAliases(ConfigurationPropertyName name,
|
||||
ConfigurationPropertyName... aliases) {
|
||||
addAlaises(name, aliases);
|
||||
addAliases(name, aliases);
|
||||
}
|
||||
|
||||
public void addAlaises(String name, String... aliases) {
|
||||
public void addAliases(String name, String... aliases) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
Assert.notNull(aliases, "Aliases must not be null");
|
||||
addAlaises(ConfigurationPropertyName.of(name),
|
||||
addAliases(ConfigurationPropertyName.of(name),
|
||||
Arrays.stream(aliases).map(ConfigurationPropertyName::of)
|
||||
.toArray(ConfigurationPropertyName[]::new));
|
||||
}
|
||||
|
||||
public void addAlaises(ConfigurationPropertyName name,
|
||||
public void addAliases(ConfigurationPropertyName name,
|
||||
ConfigurationPropertyName... aliases) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
Assert.notNull(aliases, "Aliases must not be null");
|
||||
|
|
|
@ -77,7 +77,7 @@ public interface ConfigurationPropertySource extends Iterable<ConfigurationPrope
|
|||
/**
|
||||
* Return a variant of this source that supports name aliases.
|
||||
* @param aliases a function that returns a stream of aliases for any given name
|
||||
* @return a {@link ConfigurationPropertySource} instance supporting name alaises
|
||||
* @return a {@link ConfigurationPropertySource} instance supporting name aliases
|
||||
*/
|
||||
default ConfigurationPropertySource withAliases(
|
||||
ConfigurationPropertyNameAliases aliases) {
|
||||
|
|
|
@ -47,7 +47,7 @@ public class ConfigurationPropertySources
|
|||
/**
|
||||
* The name of the {@link PropertySource} {@link #adapt adapter}.
|
||||
*/
|
||||
public static final String PROPERTY_SOURCE_NAME = "configurationPropertes";
|
||||
public static final String PROPERTY_SOURCE_NAME = "configurationProperties";
|
||||
|
||||
private final PropertySources propertySources;
|
||||
|
||||
|
|
|
@ -37,9 +37,9 @@ class DefaultPropertyMapper implements PropertyMapper {
|
|||
|
||||
public static final PropertyMapper INSTANCE = new DefaultPropertyMapper();
|
||||
|
||||
private Cache<ConfigurationPropertyName> configurationPropertySourceCache = new Cache<>();
|
||||
private final Cache<ConfigurationPropertyName> configurationPropertySourceCache = new Cache<>();
|
||||
|
||||
private Cache<String> propertySourceCache = new Cache<>();
|
||||
private final Cache<String> propertySourceCache = new Cache<>();
|
||||
|
||||
private final ConfigurationPropertyNameBuilder nameBuilder = new ConfigurationPropertyNameBuilder();
|
||||
|
||||
|
@ -59,12 +59,7 @@ class DefaultPropertyMapper implements PropertyMapper {
|
|||
@Override
|
||||
public List<PropertyMapping> map(PropertySource<?> propertySource,
|
||||
String propertySourceName) {
|
||||
List<PropertyMapping> mapping = this.propertySourceCache.get(propertySourceName);
|
||||
if (mapping == null) {
|
||||
mapping = tryMap(propertySourceName);
|
||||
this.propertySourceCache.put(propertySourceName, mapping);
|
||||
}
|
||||
return mapping;
|
||||
return this.propertySourceCache.computeIfAbsent(propertySourceName, this::tryMap);
|
||||
}
|
||||
|
||||
private List<PropertyMapping> tryMap(String propertySourceName) {
|
||||
|
@ -94,10 +89,7 @@ class DefaultPropertyMapper implements PropertyMapper {
|
|||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<K, List<PropertyMapping>> eldest) {
|
||||
if (size() < this.capacity) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return size() >= this.capacity;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public class MapConfigurationPropertySource implements ConfigurationPropertySour
|
|||
}
|
||||
|
||||
/**
|
||||
* Add all enties from the specified map.
|
||||
* Add all entries from the specified map.
|
||||
* @param map the source map
|
||||
*/
|
||||
public void putAll(Map<?, ?> map) {
|
||||
|
|
|
@ -145,7 +145,7 @@ class PropertySourceConfigurationPropertySource implements ConfigurationProperty
|
|||
return names;
|
||||
}
|
||||
List<PropertyMapping> mappings = getPropertyMappings();
|
||||
names = new ArrayList<ConfigurationPropertyName>(mappings.size());
|
||||
names = new ArrayList<>(mappings.size());
|
||||
for (PropertyMapping mapping : mappings) {
|
||||
names.add(mapping.getConfigurationPropertyName());
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ class PropertySourceConfigurationPropertySource implements ConfigurationProperty
|
|||
}
|
||||
String[] names = ((EnumerablePropertySource<?>) this.propertySource)
|
||||
.getPropertyNames();
|
||||
mappings = new ArrayList<PropertyMapping>(names.length);
|
||||
mappings = new ArrayList<>(names.length);
|
||||
for (String name : names) {
|
||||
mappings.addAll(this.mapper.map(this.propertySource, name));
|
||||
}
|
||||
|
@ -238,8 +238,6 @@ class PropertySourceConfigurationPropertySource implements ConfigurationProperty
|
|||
|
||||
private static class Cache {
|
||||
|
||||
private ConfigurationPropertyName knownMissingName;
|
||||
|
||||
private List<ConfigurationPropertyName> names;
|
||||
|
||||
private List<PropertyMapping> mappings;
|
||||
|
|
|
@ -45,7 +45,7 @@ import org.springframework.util.StringUtils;
|
|||
*/
|
||||
class SystemEnvironmentPropertyMapper implements PropertyMapper {
|
||||
|
||||
public static PropertyMapper INSTANCE = new SystemEnvironmentPropertyMapper();
|
||||
public static final PropertyMapper INSTANCE = new SystemEnvironmentPropertyMapper();
|
||||
|
||||
private final ConfigurationPropertyNameBuilder nameBuilder = new ConfigurationPropertyNameBuilder(
|
||||
this::createElement);
|
||||
|
@ -104,10 +104,9 @@ class SystemEnvironmentPropertyMapper implements PropertyMapper {
|
|||
}
|
||||
|
||||
private String convertName(ConfigurationPropertyName configurationPropertyName) {
|
||||
String propertyName = configurationPropertyName.stream()
|
||||
return configurationPropertyName.stream()
|
||||
.map(name -> name.getValue(Form.UNIFORM).toUpperCase())
|
||||
.collect(Collectors.joining("_"));
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
private boolean isListShortcutPossible(ConfigurationPropertyName name) {
|
||||
|
|
|
@ -86,7 +86,7 @@ public class TextResourceOrigin implements Origin {
|
|||
result.append(this.resource == null ? "unknown resource [?]"
|
||||
: this.resource.getDescription());
|
||||
if (this.location != null) {
|
||||
result.append(":" + this.location);
|
||||
result.append(":").append(this.location);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public class ConfigurationPropertyNameAliasesTests {
|
|||
@Test
|
||||
public void addAliasesFromStringShouldAddMapping() throws Exception {
|
||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||
aliases.addAlaises("foo", "bar", "baz");
|
||||
aliases.addAliases("foo", "bar", "baz");
|
||||
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
||||
.containsExactly(ConfigurationPropertyName.of("bar"),
|
||||
ConfigurationPropertyName.of("baz"));
|
||||
|
@ -71,7 +71,7 @@ public class ConfigurationPropertyNameAliasesTests {
|
|||
@Test
|
||||
public void addAlaisesFromNameShouldAddMapping() throws Exception {
|
||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||
aliases.addAlaises(ConfigurationPropertyName.of("foo"),
|
||||
aliases.addAliases(ConfigurationPropertyName.of("foo"),
|
||||
ConfigurationPropertyName.of("bar"), ConfigurationPropertyName.of("baz"));
|
||||
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
||||
.containsExactly(ConfigurationPropertyName.of("bar"),
|
||||
|
@ -81,8 +81,8 @@ public class ConfigurationPropertyNameAliasesTests {
|
|||
@Test
|
||||
public void addWhenHasExistingShouldAddAdditionalMappings() throws Exception {
|
||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||
aliases.addAlaises("foo", "bar");
|
||||
aliases.addAlaises("foo", "baz");
|
||||
aliases.addAliases("foo", "bar");
|
||||
aliases.addAliases("foo", "baz");
|
||||
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
||||
.containsExactly(ConfigurationPropertyName.of("bar"),
|
||||
ConfigurationPropertyName.of("baz"));
|
||||
|
@ -97,7 +97,7 @@ public class ConfigurationPropertyNameAliasesTests {
|
|||
@Test
|
||||
public void getAliasesWhenMappedShouldReturnMapping() throws Exception {
|
||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||
aliases.addAlaises("foo", "bar");
|
||||
aliases.addAliases("foo", "bar");
|
||||
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
||||
.containsExactly(ConfigurationPropertyName.of("bar"));
|
||||
}
|
||||
|
@ -105,8 +105,8 @@ public class ConfigurationPropertyNameAliasesTests {
|
|||
@Test
|
||||
public void getNameForAliasWhenHasMappingShouldReturnName() throws Exception {
|
||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||
aliases.addAlaises("foo", "bar");
|
||||
aliases.addAlaises("foo", "baz");
|
||||
aliases.addAliases("foo", "bar");
|
||||
aliases.addAliases("foo", "baz");
|
||||
assertThat((Object) aliases.getNameForAlias(ConfigurationPropertyName.of("bar")))
|
||||
.isEqualTo(ConfigurationPropertyName.of("foo"));
|
||||
assertThat((Object) aliases.getNameForAlias(ConfigurationPropertyName.of("baz")))
|
||||
|
@ -116,7 +116,7 @@ public class ConfigurationPropertyNameAliasesTests {
|
|||
@Test
|
||||
public void getNameForAliasWhenNotMappedShouldReturnNull() throws Exception {
|
||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||
aliases.addAlaises("foo", "bar");
|
||||
aliases.addAliases("foo", "bar");
|
||||
assertThat((Object) aliases.getNameForAlias(ConfigurationPropertyName.of("baz")))
|
||||
.isNull();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue