You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by lt...@apache.org on 2019/05/23 09:25:49 UTC

[incubator-iotdb] branch cluster updated: reformat code

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

lta pushed a commit to branch cluster
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/cluster by this push:
     new 7394372  reformat code
7394372 is described below

commit 7394372fb2095ad1385017a0b5d4c349116d5895
Author: lta <li...@163.com>
AuthorDate: Thu May 23 17:25:11 2019 +0800

    reformat code
---
 .../org/apache/iotdb/cluster/query/utils/ExpressionUtils.java    | 4 +---
 .../iotdb/cluster/query/utils/QueryPlanPartitionUtils.java       | 8 ++------
 .../java/org/apache/iotdb/cluster/utils/QPExecutorUtils.java     | 9 ++-------
 .../src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java  | 5 +----
 4 files changed, 6 insertions(+), 20 deletions(-)

diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/ExpressionUtils.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/ExpressionUtils.java
index 4089e9b..e6577ee 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/ExpressionUtils.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/ExpressionUtils.java
@@ -51,9 +51,7 @@ public class ExpressionUtils {
     if (expression.getType() == ExpressionType.SERIES) {
       Path path = ((SingleSeriesExpression) expression).getSeriesPath();
       String groupId = QPExecutorUtils.getGroupIdByDevice(path.getDevice());
-      if (!filterGroupEntityMap.containsKey(groupId)) {
-        filterGroupEntityMap.put(groupId, new FilterSeriesGroupEntity(groupId));
-      }
+      filterGroupEntityMap.putIfAbsent(groupId, new FilterSeriesGroupEntity(groupId));
       FilterSeriesGroupEntity filterSeriesGroupEntity = filterGroupEntityMap.get(groupId);
       filterSeriesGroupEntity.addFilterPaths(path);
       filterSeriesGroupEntity.addFilter(((SingleSeriesExpression) expression).getFilter());
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/QueryPlanPartitionUtils.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/QueryPlanPartitionUtils.java
index 03e4e7f..2b09492 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/QueryPlanPartitionUtils.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/query/utils/QueryPlanPartitionUtils.java
@@ -91,9 +91,7 @@ public class QueryPlanPartitionUtils {
     List<Path> selectPaths = queryPlan.getPaths();
     for (Path path : selectPaths) {
       String groupId = QPExecutorUtils.getGroupIdByDevice(path.getDevice());
-      if (!selectGroupEntityMap.containsKey(groupId)) {
-        selectGroupEntityMap.put(groupId, new SelectSeriesGroupEntity(groupId));
-      }
+      selectGroupEntityMap.putIfAbsent(groupId, new SelectSeriesGroupEntity(groupId));
       selectGroupEntityMap.get(groupId).addSelectPaths(path);
     }
     for (SelectSeriesGroupEntity entity : selectGroupEntityMap.values()) {
@@ -236,9 +234,7 @@ public class QueryPlanPartitionUtils {
         .getSelectSeriesGroupEntityMap();
     for (Path path : selectPaths) {
       String groupId = QPExecutorUtils.getGroupIdByDevice(path.getDevice());
-      if (!selectGroupEntityMap.containsKey(groupId)) {
-        selectGroupEntityMap.put(groupId, new SelectSeriesGroupEntity(groupId));
-      }
+      selectGroupEntityMap.putIfAbsent(groupId, new SelectSeriesGroupEntity(groupId));
       selectGroupEntityMap.get(groupId).addSelectPaths(path);
     }
     for (SelectSeriesGroupEntity entity : selectGroupEntityMap.values()) {
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/utils/QPExecutorUtils.java b/cluster/src/main/java/org/apache/iotdb/cluster/utils/QPExecutorUtils.java
index 811928c..80dec3a 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/utils/QPExecutorUtils.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/utils/QPExecutorUtils.java
@@ -88,13 +88,8 @@ public class QPExecutorUtils {
     for (int i = 0; i < sgList.size(); i++) {
       String sg = sgList.get(i);
       String groupId = router.getGroupIdBySG(sg);
-      if (map.containsKey(groupId)) {
-        map.get(groupId).add(sg);
-      } else {
-        Set<String> set = new HashSet<>();
-        set.add(sg);
-        map.put(groupId, set);
-      }
+      map.putIfAbsent(groupId, new HashSet<>());
+      map.get(groupId).add(sg);
     }
     return map;
   }
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java b/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
index 673fd12..3213472 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
@@ -144,10 +144,7 @@ public class RaftUtils {
    * @return leader id
    */
   public static PeerId getLocalLeaderPeerID(String groupId) {
-    if (!groupLeaderCache.containsKey(groupId)) {
-      PeerId randomPeerId = getRandomPeerID(groupId);
-      groupLeaderCache.put(groupId, randomPeerId);
-    }
+    groupLeaderCache.putIfAbsent(groupId, getRandomPeerID(groupId));
     PeerId leader = groupLeaderCache.get(groupId);
     LOGGER.debug("Get local cached leader {} of group {}.", leader, groupId);
     return leader;