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 2023/07/07 15:26:21 UTC
[commons-text] branch master updated (598d41eb -> d706adde)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git
from 598d41eb Inline single-use local variable
new e5eddc1a Use modern Map APIs instead of manually operating on Maps
new d706adde Use the diamond notation
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/main/java/org/apache/commons/text/StrSubstitutor.java | 14 ++++----------
.../java/org/apache/commons/text/StringSubstitutor.java | 14 ++++----------
.../org/apache/commons/text/StringSubstitutorTest.java | 2 +-
3 files changed, 9 insertions(+), 21 deletions(-)
[commons-text] 02/02: Use the diamond notation
Posted by gg...@apache.org.
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 d706adde3d7f4cfa6827a51b5c9746336f83ff37
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 7 11:26:16 2023 -0400
Use the diamond notation
---
src/test/java/org/apache/commons/text/StringSubstitutorTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java
index 93c585e3..a738c4ec 100644
--- a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java
+++ b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java
@@ -520,7 +520,7 @@ public class StringSubstitutorTest {
@Test
public void testReplaceInTakingStringBufferWithNonNull() {
- final StringSubstitutor strSubstitutor = new StringSubstitutor(new HashMap<String, String>(), "WV@i#y?N*[",
+ final StringSubstitutor strSubstitutor = new StringSubstitutor(new HashMap<>(), "WV@i#y?N*[",
"WV@i#y?N*[", '*');
assertFalse(strSubstitutor.isPreserveEscapes());
[commons-text] 01/02: Use modern Map APIs instead of manually operating on Maps
Posted by gg...@apache.org.
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 <ga...@gmail.com>
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)));
}
/**