|
22 | 22 | import java.util.Collection; |
23 | 23 | import java.util.Collections; |
24 | 24 | import java.util.HashMap; |
25 | | -import java.util.Iterator; |
26 | 25 | import java.util.LinkedList; |
27 | 26 | import java.util.List; |
28 | 27 | import java.util.Map; |
@@ -333,31 +332,25 @@ protected Collection<NewTopic> newTopics() { |
333 | 332 | Map<String, NewTopic> topicsForRetry = newTopicsMap.entrySet().stream() |
334 | 333 | .filter(entry -> entry.getValue() instanceof TopicForRetryable) |
335 | 334 | .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); |
| 335 | + Map<String, String> topicNameToMapKey = new HashMap<>(); |
| 336 | + for (Entry<String, NewTopic> entry : newTopicsMap.entrySet()) { |
| 337 | + topicNameToMapKey.put(entry.getValue().name(), entry.getKey()); |
| 338 | + } |
| 339 | + |
336 | 340 | for (Entry<String, NewTopic> entry : topicsForRetry.entrySet()) { |
337 | | - Iterator<Entry<String, NewTopic>> iterator = newTopicsMap.entrySet().iterator(); |
338 | | - boolean remove = false; |
339 | | - while (iterator.hasNext()) { |
340 | | - Entry<String, NewTopic> nt = iterator.next(); |
341 | | - // if we have a NewTopic and TopicForRetry with the same name, remove the latter |
342 | | - if (nt.getValue().name().equals(entry.getValue().name()) |
343 | | - && !(nt.getValue() instanceof TopicForRetryable)) { |
344 | | - |
345 | | - remove = true; |
346 | | - break; |
| 341 | + String retryTopicName = entry.getValue().name(); |
| 342 | + String keyInNewTopicsMap = topicNameToMapKey.get(retryTopicName); |
| 343 | + if (keyInNewTopicsMap != null) { |
| 344 | + NewTopic existing = newTopicsMap.get(keyInNewTopicsMap); |
| 345 | + if (!(existing instanceof TopicForRetryable)) { |
| 346 | + newTopicsMap.remove(keyInNewTopicsMap); |
347 | 347 | } |
348 | 348 | } |
349 | | - if (remove) { |
350 | | - newTopicsMap.remove(entry.getKey()); |
351 | | - } |
352 | 349 | } |
353 | | - Iterator<Entry<String, NewTopic>> iterator = newTopicsMap.entrySet().iterator(); |
354 | | - while (iterator.hasNext()) { |
355 | | - Entry<String, NewTopic> next = iterator.next(); |
356 | | - if (!this.createOrModifyTopic.test(next.getValue())) { |
357 | | - iterator.remove(); |
358 | | - } |
359 | | - } |
360 | | - return new ArrayList<>(newTopicsMap.values()); |
| 350 | + Map<String, NewTopic> filteredMap = newTopicsMap.entrySet().stream() |
| 351 | + .filter(entry -> this.createOrModifyTopic.test(entry.getValue())) |
| 352 | + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); |
| 353 | + return new ArrayList<>(filteredMap.values()); |
361 | 354 | } |
362 | 355 |
|
363 | 356 | @Override |
|
0 commit comments