Configuration#get return value optimization (jeagles)
This commit is contained in:
parent
675bc97f18
commit
e41aac0cd4
|
@ -611,37 +611,44 @@ 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.
|
||||||
*/
|
*/
|
||||||
private String[] handleDeprecation(DeprecationContext deprecations,
|
private String[] handleDeprecation(DeprecationContext deprecations,
|
||||||
String name) {
|
String name) {
|
||||||
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};
|
||||||
DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
|
// Deprecated keys are logged once and an updated names are returned
|
||||||
warnOnceIfDeprecated(deprecations, name);
|
DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
|
||||||
for (String newKey : keyInfo.newKeys) {
|
if (keyInfo != null) {
|
||||||
if(newKey != null) {
|
if (!keyInfo.getAndSetAccessed()) {
|
||||||
names.add(newKey);
|
logDeprecation(keyInfo.getWarningMessage(name));
|
||||||
|
}
|
||||||
|
// Override return value for deprecated keys
|
||||||
|
names = keyInfo.newKeys;
|
||||||
|
}
|
||||||
|
// If there are no overlay values we can return early
|
||||||
|
Properties overlay = getOverlay();
|
||||||
|
if (overlay.isEmpty()) {
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
// Update properties and overlays with reverse lookup values
|
||||||
|
for (String n : names) {
|
||||||
|
String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n);
|
||||||
|
if (deprecatedKey != null && !overlay.containsKey(n)) {
|
||||||
|
String deprecatedValue = overlay.getProperty(deprecatedKey);
|
||||||
|
if (deprecatedValue != null) {
|
||||||
|
getProps().setProperty(n, deprecatedValue);
|
||||||
|
overlay.setProperty(n, deprecatedValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(names.size() == 0) {
|
return names;
|
||||||
names.add(name);
|
|
||||||
}
|
|
||||||
for(String n : names) {
|
|
||||||
String deprecatedKey = deprecations.getReverseDeprecatedKeyMap().get(n);
|
|
||||||
if (deprecatedKey != null && !getOverlay().containsKey(n) &&
|
|
||||||
getOverlay().containsKey(deprecatedKey)) {
|
|
||||||
getProps().setProperty(n, getOverlay().getProperty(deprecatedKey));
|
|
||||||
getOverlay().setProperty(n, getOverlay().getProperty(deprecatedKey));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return names.toArray(new String[names.size()]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleDeprecation() {
|
private void handleDeprecation() {
|
||||||
|
@ -1179,11 +1186,8 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void warnOnceIfDeprecated(DeprecationContext deprecations, String name) {
|
private void logDeprecation(String message) {
|
||||||
DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
|
LOG_DEPRECATION.info(message);
|
||||||
if (keyInfo != null && !keyInfo.getAndSetAccessed()) {
|
|
||||||
LOG_DEPRECATION.info(keyInfo.getWarningMessage(name));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue