Skip to content

Commit

Permalink
Optimize SystemEnvironmentPropertyMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dreis2211 authored and philwebb committed Jun 5, 2020
1 parent f8d6d9a commit 0378de7
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,24 @@ private boolean isLegacyAncestorOf(ConfigurationPropertyName name, Configuration
if (!hasDashedEntries(name)) {
return false;
}
StringBuilder legacyCompatibleName = buildLegacyCompatibleName(name);
try {
return ConfigurationPropertyName.of(legacyCompatibleName).isAncestorOf(candidate);
}
catch (Exception ex) {
return false;
}
}

private StringBuilder buildLegacyCompatibleName(ConfigurationPropertyName name) {
StringBuilder legacyCompatibleName = new StringBuilder();
for (int i = 0; i < name.getNumberOfElements(); i++) {
if (i != 0) {
legacyCompatibleName.append('.');
}
legacyCompatibleName.append(name.getElement(i, Form.DASHED).replace('-', '.'));
}
return ConfigurationPropertyName.isValid(legacyCompatibleName)
&& ConfigurationPropertyName.of(legacyCompatibleName).isAncestorOf(candidate);
return legacyCompatibleName;
}

boolean hasDashedEntries(ConfigurationPropertyName name) {
Expand Down

0 comments on commit 0378de7

Please sign in to comment.