private String replaceValue(String propertyValue) {
        // Use a list with keys sorted by length (longest key first)
        // Needed for replacing values where you have overlapping keys
        ArrayList<String> keys = new ArrayList<>(properties.keySet());
        keys.sort(Collections.reverseOrder(Comparator.comparing(String::length)));

        for (String key : keys) {
            String value = properties.get(key);
            // Try to find exact match first and since this is done with longest key
            // first, the else branch will only happen when there cannot be an exact
            // match, i.e. where you want to replace only parts of the attribute or node value
            if (propertyValue.equals("${" + key + "}")) {
                String regex = "\\$\\{" + key + "}";
                return propertyValue.replaceAll(regex, value);
            } else if (propertyValue.contains(key)) {
                return propertyValue.replaceAll("\\$\\{" + key + "}", value);
            }
        }
        throw new IllegalArgumentException("Unable to find property replace in " + propertyValue);
    }
Handles getting properties from services.xml and replacing references to properties with their real values

@author hmusum
config-application-package/src/main/java/com/yahoo/config/application/PropertiesProcessor.java