You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/12/07 03:15:56 UTC

[GitHub] [rocketmq] zhaohai1299002788 opened a new pull request #3595: entrySet() replace keySet()

zhaohai1299002788 opened a new pull request #3595:
URL: https://github.com/apache/rocketmq/pull/3595


   There are several inefficient iterations of Map, in such code, keySet() is retrieved from Map firstly, and values are got in each iteration by key. In my opinion, entrySet() should be used, so that keys and values can be fetched in one time.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] coveralls edited a comment on pull request #3595: [ISSUE #3593] entrySet() replace keySet()

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #3595:
URL: https://github.com/apache/rocketmq/pull/3595#issuecomment-987535259


   
   [![Coverage Status](https://coveralls.io/builds/44873190/badge)](https://coveralls.io/builds/44873190)
   
   Coverage increased (+0.1%) to 55.236% when pulling **f5497d2c8e67fdb7235e4d3455bcc6bd0e3ff141 on zhaohai1299002788:inefficient_iteration_of_map** into **4d495515acab8f2f2fbbd76872c007f2d01c891e on apache:develop**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] coveralls edited a comment on pull request #3595: [ISSUE #3593] entrySet() replace keySet()

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #3595:
URL: https://github.com/apache/rocketmq/pull/3595#issuecomment-987535259


   
   [![Coverage Status](https://coveralls.io/builds/44809511/badge)](https://coveralls.io/builds/44809511)
   
   Coverage increased (+0.04%) to 55.126% when pulling **be56cb8beb98904f5ef5528d87d03556254fbe75 on zhaohai1299002788:inefficient_iteration_of_map** into **4d495515acab8f2f2fbbd76872c007f2d01c891e on apache:develop**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] Git-Yang commented on pull request #3595: [ISSUE #3593] entrySet() replace keySet()

Posted by GitBox <gi...@apache.org>.
Git-Yang commented on pull request #3595:
URL: https://github.com/apache/rocketmq/pull/3595#issuecomment-987829786


   /home/travis/build/apache/rocketmq/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMachineRoomNearby.java:23:8: error: Unused import - java.util.Set.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] coveralls edited a comment on pull request #3595: [ISSUE #3593] entrySet() replace keySet()

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #3595:
URL: https://github.com/apache/rocketmq/pull/3595#issuecomment-987535259


   
   [![Coverage Status](https://coveralls.io/builds/44838078/badge)](https://coveralls.io/builds/44838078)
   
   Coverage decreased (-0.02%) to 55.07% when pulling **1b71e953a293d42b2d4d186b85ab559bcbe42c19 on zhaohai1299002788:inefficient_iteration_of_map** into **4d495515acab8f2f2fbbd76872c007f2d01c891e on apache:develop**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] zhaohai1299002788 commented on a change in pull request #3595: [ISSUE #3593] entrySet() replace keySet()

Posted by GitBox <gi...@apache.org>.
zhaohai1299002788 commented on a change in pull request #3595:
URL: https://github.com/apache/rocketmq/pull/3595#discussion_r763671092



##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java
##########
@@ -83,19 +86,19 @@ public void execute(final CommandLine commandLine, final Options options,
                 Map<String, List<String>> masterAndSlaveMap
                     = CommandUtil.fetchMasterAndSlaveDistinguish(defaultMQAdminExt, clusterName);
 
-                for (String masterAddr : masterAndSlaveMap.keySet()) {
+                for (Entry<String, List<String>> masterAddrEntry : masterAndSlaveMap.entrySet()) {

Review comment:
       already edited

##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java
##########
@@ -121,8 +124,8 @@ protected void getAndPrint(final MQAdminExt defaultMQAdminExt, final String prin
             return;
         }
 
-        for (Object key : properties.keySet()) {
-            System.out.printf("%-50s=  %s\n", key, properties.get(key));
+        for (Entry<Object, Object> keyEntry : properties.entrySet()) {
+            System.out.printf("%-50s=  %s\n", keyEntry.getKey(), keyEntry.getValue());

Review comment:
       already edited

##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/consumer/GetConsumerConfigSubCommand.java
##########
@@ -63,14 +65,14 @@ public void execute(CommandLine commandLine, Options options,
             List<ConsumerConfigInfo> consumerConfigInfoList = new ArrayList<>();
             ClusterInfo clusterInfo = adminExt.examineBrokerClusterInfo();
             Map<String, Set<String>> clusterAddrTable = clusterInfo.getClusterAddrTable();
-            for (String brokerName : clusterInfo.getBrokerAddrTable().keySet()) {
-                String clusterName = this.getClusterName(brokerName, clusterAddrTable);
-                String brokerAddress = clusterInfo.getBrokerAddrTable().get(brokerName).selectBrokerAddr();
+            for (Entry<String, BrokerData> brokerNameEntry : clusterInfo.getBrokerAddrTable().entrySet()) {

Review comment:
       already edited

##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/export/ExportConfigsCommand.java
##########
@@ -79,10 +81,10 @@ public void execute(CommandLine commandLine, Options options, RPCHook rpcHook)
             Map<String, Properties> brokerConfigs = new HashMap<>();
             Map<String, List<String>> masterAndSlaveMap
                 = CommandUtil.fetchMasterAndSlaveDistinguish(defaultMQAdminExt, clusterName);
-            for (String masterAddr : masterAndSlaveMap.keySet()) {
-                Properties masterProperties = defaultMQAdminExt.getBrokerConfig(masterAddr);
+            for (Entry<String, List<String>> masterAddrEntry : masterAndSlaveMap.entrySet()) {

Review comment:
       already edited

##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommand.java
##########
@@ -66,11 +69,11 @@ public void execute(final CommandLine commandLine, final Options options,
 
             Map<String, Properties> nameServerConfigs = defaultMQAdminExt.getNameServerConfig(serverList);
 
-            for (String server : nameServerConfigs.keySet()) {
+            for (Entry<String, Properties> serverEntry : nameServerConfigs.entrySet()) {

Review comment:
       already edited




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] yuz10 commented on a change in pull request #3595: [ISSUE #3593] entrySet() replace keySet()

Posted by GitBox <gi...@apache.org>.
yuz10 commented on a change in pull request #3595:
URL: https://github.com/apache/rocketmq/pull/3595#discussion_r763604377



##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java
##########
@@ -83,19 +86,19 @@ public void execute(final CommandLine commandLine, final Options options,
                 Map<String, List<String>> masterAndSlaveMap
                     = CommandUtil.fetchMasterAndSlaveDistinguish(defaultMQAdminExt, clusterName);
 
-                for (String masterAddr : masterAndSlaveMap.keySet()) {
+                for (Entry<String, List<String>> masterAddrEntry : masterAndSlaveMap.entrySet()) {

Review comment:
       masterAddrEntry could be renamed to masterAndSlaveEntry

##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java
##########
@@ -121,8 +124,8 @@ protected void getAndPrint(final MQAdminExt defaultMQAdminExt, final String prin
             return;
         }
 
-        for (Object key : properties.keySet()) {
-            System.out.printf("%-50s=  %s\n", key, properties.get(key));
+        for (Entry<Object, Object> keyEntry : properties.entrySet()) {
+            System.out.printf("%-50s=  %s\n", keyEntry.getKey(), keyEntry.getValue());

Review comment:
       keyEntry could be renamed to entry, and so is the obove

##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/consumer/GetConsumerConfigSubCommand.java
##########
@@ -63,14 +65,14 @@ public void execute(CommandLine commandLine, Options options,
             List<ConsumerConfigInfo> consumerConfigInfoList = new ArrayList<>();
             ClusterInfo clusterInfo = adminExt.examineBrokerClusterInfo();
             Map<String, Set<String>> clusterAddrTable = clusterInfo.getClusterAddrTable();
-            for (String brokerName : clusterInfo.getBrokerAddrTable().keySet()) {
-                String clusterName = this.getClusterName(brokerName, clusterAddrTable);
-                String brokerAddress = clusterInfo.getBrokerAddrTable().get(brokerName).selectBrokerAddr();
+            for (Entry<String, BrokerData> brokerNameEntry : clusterInfo.getBrokerAddrTable().entrySet()) {

Review comment:
       brokerNameEntry could be rename to brokerEntry

##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/export/ExportConfigsCommand.java
##########
@@ -79,10 +81,10 @@ public void execute(CommandLine commandLine, Options options, RPCHook rpcHook)
             Map<String, Properties> brokerConfigs = new HashMap<>();
             Map<String, List<String>> masterAndSlaveMap
                 = CommandUtil.fetchMasterAndSlaveDistinguish(defaultMQAdminExt, clusterName);
-            for (String masterAddr : masterAndSlaveMap.keySet()) {
-                Properties masterProperties = defaultMQAdminExt.getBrokerConfig(masterAddr);
+            for (Entry<String, List<String>> masterAddrEntry : masterAndSlaveMap.entrySet()) {

Review comment:
       masterAddrEntry could be renamed to masterAndSlaveEntry

##########
File path: test/src/main/java/org/apache/rocketmq/test/util/MQAdmin.java
##########
@@ -123,10 +124,10 @@ public static boolean isBrokerExist(String ns, String ip) {
             return false;
         } else {
             HashMap<String, BrokerData> brokers = clusterInfo.getBrokerAddrTable();
-            for (String brokerName : brokers.keySet()) {
-                HashMap<Long, String> brokerIps = brokers.get(brokerName).getBrokerAddrs();
-                for (long brokerId : brokerIps.keySet()) {
-                    if (brokerIps.get(brokerId).contains(ip))
+            for (Entry<String, BrokerData> brokerNameEntry : brokers.entrySet()) {

Review comment:
       brokerNameEntry could be renamed to brokerEntry

##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/CommandUtil.java
##########
@@ -63,12 +64,12 @@
             String masterAddr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
             masterAndSlaveMap.put(masterAddr, new ArrayList<String>());
 
-            for (Long id : brokerData.getBrokerAddrs().keySet()) {
-                if (brokerData.getBrokerAddrs().get(id) == null || id == MixAll.MASTER_ID) {
+            for (Entry<Long, String> idEntry : brokerData.getBrokerAddrs().entrySet()) {
+                if (idEntry.getValue() == null || idEntry.getKey() == MixAll.MASTER_ID) {

Review comment:
       idEntry could be renamed to brokerAddrEntry

##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommand.java
##########
@@ -66,11 +69,11 @@ public void execute(final CommandLine commandLine, final Options options,
 
             Map<String, Properties> nameServerConfigs = defaultMQAdminExt.getNameServerConfig(serverList);
 
-            for (String server : nameServerConfigs.keySet()) {
+            for (Entry<String, Properties> serverEntry : nameServerConfigs.entrySet()) {

Review comment:
       serverEntry could be renamed to nameServerConfigEntry




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] coveralls commented on pull request #3595: [ISSUE #3593] entrySet() replace keySet()

Posted by GitBox <gi...@apache.org>.
coveralls commented on pull request #3595:
URL: https://github.com/apache/rocketmq/pull/3595#issuecomment-987535259


   
   [![Coverage Status](https://coveralls.io/builds/44806538/badge)](https://coveralls.io/builds/44806538)
   
   Coverage increased (+0.01%) to 55.103% when pulling **fbe677e0bb99222211ab177caa4818ddf96c5c56 on zhaohai1299002788:inefficient_iteration_of_map** into **4d495515acab8f2f2fbbd76872c007f2d01c891e on apache:develop**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] Git-Yang commented on pull request #3595: [ISSUE #3593] entrySet() replace keySet()

Posted by GitBox <gi...@apache.org>.
Git-Yang commented on pull request #3595:
URL: https://github.com/apache/rocketmq/pull/3595#issuecomment-989578419


   link https://github.com/apache/rocketmq/issues/3593


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] zhaohai1299002788 commented on a change in pull request #3595: [ISSUE #3593] entrySet() replace keySet()

Posted by GitBox <gi...@apache.org>.
zhaohai1299002788 commented on a change in pull request #3595:
URL: https://github.com/apache/rocketmq/pull/3595#discussion_r763670502



##########
File path: test/src/main/java/org/apache/rocketmq/test/util/MQAdmin.java
##########
@@ -123,10 +124,10 @@ public static boolean isBrokerExist(String ns, String ip) {
             return false;
         } else {
             HashMap<String, BrokerData> brokers = clusterInfo.getBrokerAddrTable();
-            for (String brokerName : brokers.keySet()) {
-                HashMap<Long, String> brokerIps = brokers.get(brokerName).getBrokerAddrs();
-                for (long brokerId : brokerIps.keySet()) {
-                    if (brokerIps.get(brokerId).contains(ip))
+            for (Entry<String, BrokerData> brokerNameEntry : brokers.entrySet()) {

Review comment:
       already edited




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq] Git-Yang merged pull request #3595: [ISSUE #3593] entrySet() replace keySet()

Posted by GitBox <gi...@apache.org>.
Git-Yang merged pull request #3595:
URL: https://github.com/apache/rocketmq/pull/3595


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org