chickenlj commented on pull request #9780:
URL: https://github.com/apache/dubbo/pull/9780#issuecomment-1067534633


   > Hi chickenlj
   > 
   > by the way ,The project cannot use stream? This code was not approve?
   > 
   > ```
   > public static int getConsumerAddressNum(ConsumerModel consumerModel) {
   >         // TODO, only check one registry by default.
   >         int num = 0;
   > 
   >         RegistryManager registryManager = 
consumerModel.getModuleModel().getApplicationModel().getBeanFactory().getBean(RegistryManager.class);
   >         Collection<Registry> registries = registryManager.getRegistries();
   >         if (CollectionUtils.isEmpty(registries)) {
   >             return num;
   >         }
   >         return registries.stream()
   >             .filter(v -> v instanceof AbstractRegistry)
   >             .findFirst()
   >             .map(v -> (AbstractRegistry)v)
   >             .flatMap(abstractRegistry -> 
abstractRegistry.getNotified().entrySet().stream()
   >                 .filter(kv -> 
kv.getKey().getServiceKey().equals(consumerModel.getServiceKey()))
   >                 .filter(kv -> CollectionUtils.isNotEmptyMap(kv.getValue()))
   >                 .findFirst()
   >                 .map(kv -> kv.getValue().size()))
   >             .orElse(num);
   >     }
   > ```
   
   There's no restriction on using stream. For this case, we'd better not use 
the stream for the following reasons:
   1. Avoid unnecessary code refactor for potential bugs.
   2. I don't see the stream snippet above more clear than the previous for 
loop.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to