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-text.git

commit e5eddc1aadc9e5658f216d8d2dfe568d29c245b3
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Jul 7 11:26:05 2023 -0400

    Use modern Map APIs instead of manually operating on Maps
---
 src/main/java/org/apache/commons/text/StrSubstitutor.java  | 14 ++++----------
 .../java/org/apache/commons/text/StringSubstitutor.java    | 14 ++++----------
 2 files changed, 8 insertions(+), 20 deletions(-)

diff --git a/src/main/java/org/apache/commons/text/StrSubstitutor.java 
b/src/main/java/org/apache/commons/text/StrSubstitutor.java
index 8a713834..9e0b970d 100644
--- a/src/main/java/org/apache/commons/text/StrSubstitutor.java
+++ b/src/main/java/org/apache/commons/text/StrSubstitutor.java
@@ -17,11 +17,11 @@
 package org.apache.commons.text;
 
 import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 import org.apache.commons.lang3.Validate;
 
@@ -191,14 +191,8 @@ public class StrSubstitutor {
         if (valueProperties == null) {
             return source.toString();
         }
-        final Map<String, String> valueMap = new HashMap<>();
-        final Enumeration<?> propNames = valueProperties.propertyNames();
-        while (propNames.hasMoreElements()) {
-            final String propName = String.valueOf(propNames.nextElement());
-            final String propValue = valueProperties.getProperty(propName);
-            valueMap.put(propName, propValue);
-        }
-        return StrSubstitutor.replace(source, valueMap);
+        return StrSubstitutor.replace(source,
+                
valueProperties.stringPropertyNames().stream().collect(Collectors.toMap(Function.identity(),
 valueProperties::getProperty)));
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/text/StringSubstitutor.java 
b/src/main/java/org/apache/commons/text/StringSubstitutor.java
index 3b1e4cb7..3d316ec2 100644
--- a/src/main/java/org/apache/commons/text/StringSubstitutor.java
+++ b/src/main/java/org/apache/commons/text/StringSubstitutor.java
@@ -17,12 +17,12 @@
 package org.apache.commons.text;
 
 import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Properties;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 import org.apache.commons.lang3.Validate;
 import org.apache.commons.text.lookup.StringLookup;
@@ -421,14 +421,8 @@ public class StringSubstitutor {
         if (valueProperties == null) {
             return source.toString();
         }
-        final Map<String, String> valueMap = new HashMap<>();
-        final Enumeration<?> propNames = valueProperties.propertyNames();
-        while (propNames.hasMoreElements()) {
-            final String propName = String.valueOf(propNames.nextElement());
-            final String propValue = valueProperties.getProperty(propName);
-            valueMap.put(propName, propValue);
-        }
-        return StringSubstitutor.replace(source, valueMap);
+        return StringSubstitutor.replace(source,
+                
valueProperties.stringPropertyNames().stream().collect(Collectors.toMap(Function.identity(),
 valueProperties::getProperty)));
     }
 
     /**

Reply via email to