You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/07/05 00:27:45 UTC

[commons-configuration] branch master updated: Add Apache Commons Text lookups but don't override existing keys. This will allow future Apache Commons Text in future versions > 1.7 to kick in automatically. Currently the lookups are the same.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-configuration.git


The following commit(s) were added to refs/heads/master by this push:
     new 2a34df1  Add Apache Commons Text lookups but don't override existing keys. This will allow future Apache Commons Text in future versions > 1.7 to kick in automatically. Currently the lookups are the same.
2a34df1 is described below

commit 2a34df18e402f1548aa15f993c2fe6074cc22bac
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Jul 4 20:27:41 2019 -0400

    Add Apache Commons Text lookups but don't override existing keys. This
    will allow future Apache Commons Text in future versions > 1.7 to kick
    in automatically. Currently the lookups are the same.
---
 .../configuration2/interpol/ConfigurationInterpolator.java | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/configuration2/interpol/ConfigurationInterpolator.java b/src/main/java/org/apache/commons/configuration2/interpol/ConfigurationInterpolator.java
index ed84a08..93dff54 100644
--- a/src/main/java/org/apache/commons/configuration2/interpol/ConfigurationInterpolator.java
+++ b/src/main/java/org/apache/commons/configuration2/interpol/ConfigurationInterpolator.java
@@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.commons.text.StringSubstitutor;
+import org.apache.commons.text.lookup.DefaultStringLookup;
 import org.apache.commons.text.lookup.StringLookup;
 
 /**
@@ -107,10 +108,17 @@ public class ConfigurationInterpolator
 
     static
     {
-        final Map<String, Lookup> lookups = new HashMap<>(DefaultLookups.values().length);
-        for (final DefaultLookups l : DefaultLookups.values())
+        // TODO Perhaps a 3.0 version should only use Commons Text lookups.
+        // Add our own lookups.
+        final Map<String, Lookup> lookups = new HashMap<>();
+        for (final DefaultLookups lookup : DefaultLookups.values())
         {
-            lookups.put(l.getPrefix(), l.getLookup());
+            lookups.put(lookup.getPrefix(), lookup.getLookup());
+        }
+        // Add Apache Commons Text lookups but don't override existing keys.
+        for (final DefaultStringLookup lookup : DefaultStringLookup.values())
+        {
+            lookups.putIfAbsent(lookup.getKey(), new StringLookupAdapter(lookup.getStringLookup()));
         }
         DEFAULT_PREFIX_LOOKUPS = Collections.unmodifiableMap(lookups);
     }