You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/03/18 04:48:28 UTC

[shardingsphere] branch master updated: Refactor DataNodes (#9716)

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

panjuan 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 df07ad2  Refactor DataNodes (#9716)
df07ad2 is described below

commit df07ad2dce6decc304189e576f73849a1f1287cd
Author: Liang Zhang <te...@163.com>
AuthorDate: Thu Mar 18 12:47:58 2021 +0800

    Refactor DataNodes (#9716)
---
 .../shardingsphere/infra/datanode/DataNodes.java       | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
index 8b37796..ecbd2a7 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
@@ -55,33 +55,29 @@ public final class DataNodes {
         for (ShardingSphereRule each : rules) {
             if (each instanceof DataSourceContainedRule) {
                 for (Entry<String, Collection<String>> entry : ((DataSourceContainedRule) each).getDataSourceMapper().entrySet()) {
-                    Collection<DataNode> dataNodes = find(result, entry.getKey());
+                    Collection<DataNode> dataNodes = findDataNodes(result, entry.getKey());
                     result.removeAll(dataNodes);
-                    result.addAll(regenerate(dataNodes, entry.getValue()));
+                    result.addAll(rebuildDataNodes(dataNodes, entry.getValue()));
                 }
             }
         }
         return result;
     }
     
-    private Collection<DataNode> find(final Collection<DataNode> dataNodes, final String logicDataSource) {
+    private Collection<DataNode> findDataNodes(final Collection<DataNode> dataNodes, final String logicDataSource) {
         return dataNodes.stream().filter(each -> each.getDataSourceName().equals(logicDataSource)).collect(Collectors.toList());
     }
     
-    private Collection<DataNode> regenerate(final Collection<DataNode> dataNodes, final Collection<String> actualDataSources) {
+    private Collection<DataNode> rebuildDataNodes(final Collection<DataNode> dataNodes, final Collection<String> actualDataSources) {
         Collection<DataNode> result = new LinkedHashSet<>();
         for (DataNode each : dataNodes) {
-            result.addAll(regenerate(actualDataSources, each.getTableName()));
+            result.addAll(rebuildDataNodes(actualDataSources, each.getTableName()));
         }
         return result;
     }
     
-    private Collection<DataNode> regenerate(final Collection<String> dataSources, final String table) {
-        Collection<DataNode> result = new LinkedHashSet<>(dataSources.size(), 1);
-        for (String each : dataSources) {
-            result.add(new DataNode(each, table));
-        }
-        return result;
+    private Collection<DataNode> rebuildDataNodes(final Collection<String> dataSources, final String table) {
+        return dataSources.stream().map(each -> new DataNode(each, table)).collect(Collectors.toCollection(() -> new LinkedHashSet<>(dataSources.size(), 1)));
     }
     
     /**