Configuration#get return value optimization (jeagles)
This commit is contained in:
parent
858d597be0
commit
db2adf356a
|
@ -619,6 +619,7 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
||||||
* deprecated key, the value of the deprecated key is set as the value for
|
* deprecated key, the value of the deprecated key is set as the value for
|
||||||
* the provided property name.
|
* the provided property name.
|
||||||
*
|
*
|
||||||
|
* @param deprecations deprecation context
|
||||||
* @param name the property name
|
* @param name the property name
|
||||||
* @return the first property in the list of properties mapping
|
* @return the first property in the list of properties mapping
|
||||||
* the <code>name</code> or the <code>name</code> itself.
|
* the <code>name</code> or the <code>name</code> itself.
|
||||||
|
@ -628,33 +629,34 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
||||||
if (null != name) {
|
if (null != name) {
|
||||||
name = name.trim();
|
name = name.trim();
|
||||||
}
|
}
|
||||||
ArrayList<String > names = new ArrayList<String>();
|
// Initialize the return value with requested name
|
||||||
if (isDeprecated(name)) {
|
String[] names = new String[]{name};
|
||||||
|
// Deprecated keys are logged once and an updated names are returned
|
||||||
DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
|
DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
|
||||||
if (keyInfo != null) {
|
if (keyInfo != null) {
|
||||||
if (!keyInfo.getAndSetAccessed()) {
|
if (!keyInfo.getAndSetAccessed()) {
|
||||||
logDeprecation(keyInfo.getWarningMessage(name));
|
logDeprecation(keyInfo.getWarningMessage(name));
|
||||||
}
|
}
|
||||||
|
// Override return value for deprecated keys
|
||||||
for (String newKey : keyInfo.newKeys) {
|
names = keyInfo.newKeys;
|
||||||
if (newKey != null) {
|
|
||||||
names.add(newKey);
|
|
||||||
}
|
}
|
||||||
|
// If there are no overlay values we can return early
|
||||||
|
Properties overlayProperties = getOverlay();
|
||||||
|
if (overlayProperties.isEmpty()) {
|
||||||
|
return names;
|
||||||
}
|
}
|
||||||
}
|
// Update properties and overlays with reverse lookup values
|
||||||
}
|
for (String n : names) {
|
||||||
if(names.size() == 0) {
|
|
||||||
names.add(name);
|
|
||||||
}
|
|
||||||
for(String n : names) {
|
|
||||||
String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n);
|
String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n);
|
||||||
if (deprecatedKey != null && !getOverlay().containsKey(n) &&
|
if (deprecatedKey != null && !overlayProperties.containsKey(n)) {
|
||||||
getOverlay().containsKey(deprecatedKey)) {
|
String deprecatedValue = overlayProperties.getProperty(deprecatedKey);
|
||||||
getProps().setProperty(n, getOverlay().getProperty(deprecatedKey));
|
if (deprecatedValue != null) {
|
||||||
getOverlay().setProperty(n, getOverlay().getProperty(deprecatedKey));
|
getProps().setProperty(n, deprecatedValue);
|
||||||
|
overlayProperties.setProperty(n, deprecatedValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return names.toArray(new String[names.size()]);
|
}
|
||||||
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleDeprecation() {
|
private void handleDeprecation() {
|
||||||
|
|
Loading…
Reference in New Issue