Please note that this report is not reproducible via any release. See collector-sahab#252
Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Loading status checks…
remove redundant code (#9089)
* Modifying duplicate code,remove unnecessary if * remove [instance.getIp() + ":" + instance.getPort()] and use the original Instance.toIpAddr() method,Because their implementation is the same
Showing
1 changed file
with
7 additions
and
14 deletions.
There are no files selected for viewing
21 changes: 7 additions & 14 deletions
21
naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| } | |||
| } | |||
| private List<Instance> updatedIps(Collection<Instance> newInstance, Collection<Instance> oldInstance) { | |||
| List<Instance> intersects = (List<Instance>) CollectionUtils.intersection(newInstance, oldInstance); | |||
| Map<String, Instance> stringIpAddressMap = new ConcurrentHashMap<>(intersects.size()); | |||
|
|
|||
| for (Instance instance : intersects) { | |||
| stringIpAddressMap.put(instance.getIp() + ":" + instance.getPort(), instance); | |||
| stringIpAddressMap.put(instance.toIpAddr(), instance); | |||
| } | |||
|
|
|||
| Map<String, Integer> intersectMap = new ConcurrentHashMap<>(newInstance.size() + oldInstance.size()); | |||
| Map<String, Instance> updatedInstancesMap = new ConcurrentHashMap<>(newInstance.size()); | |||
| Map<String, Instance> newInstancesMap = new ConcurrentHashMap<>(newInstance.size()); | |||
|
|
|||
| for (Instance instance : oldInstance) { | |||
| if (stringIpAddressMap.containsKey(instance.getIp() + ":" + instance.getPort())) { | |||
| if (stringIpAddressMap.containsKey(instance.toIpAddr())) { | |||
| intersectMap.put(instance.toString(), 1); | |||
| } | |||
| } | |||
|
|
|||
| for (Instance instance : newInstance) { | |||
| if (stringIpAddressMap.containsKey(instance.getIp() + ":" + instance.getPort())) { | |||
|
|
|||
| if (intersectMap.containsKey(instance.toString())) { | |||
| intersectMap.put(instance.toString(), 2); | |||
| } else { | |||
| intersectMap.put(instance.toString(), 1); | |||
| } | |||
| if (stringIpAddressMap.containsKey(instance.toIpAddr())) { | |||
| intersectMap.put(instance.toString(), intersectMap.containsKey(instance.toString()) ? 2 : 1); | |||
| } | |||
|
|
|||
| newInstancesMap.put(instance.toString(), instance); | |||
|
|||
|
|||
| } | |||
| for (Map.Entry<String, Integer> entry : intersectMap.entrySet()) { | |||
| String key = entry.getKey(); | |||
| Integer value = entry.getValue(); | |||
|
|
|||
| if (value == 1) { | |||
| if (newInstancesMap.containsKey(key)) { | |||
| updatedInstancesMap.put(key, newInstancesMap.get(key)); | |||
| } | |||
|
|
|||
| if (value == 1 && newInstancesMap.containsKey(key)) { | |||
| updatedInstancesMap.put(key, newInstancesMap.get(key)); | |||
| } | |||
| } | |||
|
|
|||
| return new ArrayList<>(updatedInstancesMap.values()); | |||
| } | |||
| private List<Instance> subtract(Collection<Instance> oldIp, Collection<Instance> ips) { | |||