@ -16,9 +16,6 @@
package org.springframework.boot.context.properties.source ;
package org.springframework.boot.context.properties.source ;
import java.util.Collections ;
import java.util.List ;
import org.springframework.util.ObjectUtils ;
import org.springframework.util.ObjectUtils ;
/ * *
/ * *
@ -43,55 +40,53 @@ final class DefaultPropertyMapper implements PropertyMapper {
}
}
@Override
@Override
public List < PropertyMapping > map (
public PropertyMapping [ ] map ( ConfigurationPropertyName configurationPropertyName ) {
ConfigurationPropertyName configurationPropertyName ) {
// Use a local copy in case another thread changes things
// Use a local copy in case another thread changes things
LastMapping < ConfigurationPropertyName > last = this . lastMappedConfigurationPropertyName ;
LastMapping < ConfigurationPropertyName > last = this . lastMappedConfigurationPropertyName ;
if ( last ! = null & & last . isFrom ( configurationPropertyName ) ) {
if ( last ! = null & & last . isFrom ( configurationPropertyName ) ) {
return last . getMapping ( ) ;
return last . getMapping ( ) ;
}
}
String convertedName = configurationPropertyName . toString ( ) ;
String convertedName = configurationPropertyName . toString ( ) ;
List < PropertyMapping > mapping = Collections . singletonList (
PropertyMapping [ ] mapping = {
new PropertyMapping ( convertedName , configurationPropertyName ) ) ;
new PropertyMapping ( convertedName , configurationPropertyName ) } ;
this . lastMappedConfigurationPropertyName = new LastMapping < > (
this . lastMappedConfigurationPropertyName = new LastMapping < > (
configurationPropertyName , mapping ) ;
configurationPropertyName , mapping ) ;
return mapping ;
return mapping ;
}
}
@Override
@Override
public List < PropertyMapping > map ( String propertySourceName ) {
public PropertyMapping [ ] map ( String propertySourceName ) {
// Use a local copy in case another thread changes things
// Use a local copy in case another thread changes things
LastMapping < String > last = this . lastMappedPropertyName ;
LastMapping < String > last = this . lastMappedPropertyName ;
if ( last ! = null & & last . isFrom ( propertySourceName ) ) {
if ( last ! = null & & last . isFrom ( propertySourceName ) ) {
return last . getMapping ( ) ;
return last . getMapping ( ) ;
}
}
List < PropertyMapping > mapping = tryMap ( propertySourceName ) ;
PropertyMapping [ ] mapping = tryMap ( propertySourceName ) ;
this . lastMappedPropertyName = new LastMapping < > ( propertySourceName , mapping ) ;
this . lastMappedPropertyName = new LastMapping < > ( propertySourceName , mapping ) ;
return mapping ;
return mapping ;
}
}
private List < PropertyMapping > tryMap ( String propertySourceName ) {
private PropertyMapping [ ] tryMap ( String propertySourceName ) {
try {
try {
ConfigurationPropertyName convertedName = ConfigurationPropertyName
ConfigurationPropertyName convertedName = ConfigurationPropertyName
. adapt ( propertySourceName , '.' ) ;
. adapt ( propertySourceName , '.' ) ;
if ( ! convertedName . isEmpty ( ) ) {
if ( ! convertedName . isEmpty ( ) ) {
PropertyMapping o = new PropertyMapping ( propertySourceName ,
return new PropertyMapping [ ] {
convertedName ) ;
new PropertyMapping ( propertySourceName , convertedName ) } ;
return Collections . singletonList ( o ) ;
}
}
}
}
catch ( Exception ex ) {
catch ( Exception ex ) {
}
}
return Collections . emptyList ( ) ;
return NO_MAPPINGS ;
}
}
private static class LastMapping < T > {
private static class LastMapping < T > {
private final T from ;
private final T from ;
private final List < PropertyMapping > mapping ;
private final PropertyMapping [ ] mapping ;
LastMapping ( T from , List < PropertyMapping > mapping ) {
LastMapping ( T from , PropertyMapping [ ] mapping ) {
this . from = from ;
this . from = from ;
this . mapping = mapping ;
this . mapping = mapping ;
}
}
@ -100,7 +95,7 @@ final class DefaultPropertyMapper implements PropertyMapper {
return ObjectUtils . nullSafeEquals ( from , this . from ) ;
return ObjectUtils . nullSafeEquals ( from , this . from ) ;
}
}
public List < PropertyMapping > getMapping ( ) {
public PropertyMapping [ ] getMapping ( ) {
return this . mapping ;
return this . mapping ;
}
}