You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/03/15 03:52:47 UTC

[GitHub] [dubbo] chickenlj commented on pull request #9780: Add instanceOf before class cast

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: notifications-unsubscribe@dubbo.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org