You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/10/15 10:16:13 UTC

(shardingsphere) branch master updated: Refactor PropertiesUtils (#33255)

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

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 16c025c55f5 Refactor PropertiesUtils (#33255)
16c025c55f5 is described below

commit 16c025c55f5ab42505baec869692b24832815ad2
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Oct 15 18:16:07 2024 +0800

    Refactor PropertiesUtils (#33255)
---
 .../infra/util/props/PropertiesUtils.java              | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/props/PropertiesUtils.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/props/PropertiesUtils.java
index a51d26ff4ab..4fd215df248 100644
--- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/props/PropertiesUtils.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/props/PropertiesUtils.java
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.infra.util.props;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 
-import java.util.Iterator;
 import java.util.Properties;
 import java.util.TreeMap;
+import java.util.stream.Collectors;
 
 /**
  * Properties utilities.
@@ -36,21 +36,7 @@ public final class PropertiesUtils {
      * @param props properties
      * @return properties string
      */
-    @SuppressWarnings({"unchecked", "rawtypes"})
     public static String toString(final Properties props) {
-        StringBuilder result = new StringBuilder();
-        Iterator<String> iterator = new TreeMap(props).keySet().iterator();
-        while (iterator.hasNext()) {
-            String key = iterator.next();
-            Object value = props.get(key);
-            if (null == value) {
-                continue;
-            }
-            result.append(String.format("'%s'='%s'", key, value));
-            if (iterator.hasNext()) {
-                result.append(",").append(' ');
-            }
-        }
-        return result.toString();
+        return new TreeMap<>(props).entrySet().stream().map(entry -> String.format("'%s'='%s'", entry.getKey(), entry.getValue())).collect(Collectors.joining(", "));
     }
 }