|
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;
|
|
81 | 80 | * @author Valentina Armenise
|
82 | 81 | * @author Anders Swanson
|
83 | 82 | * @author Omer Celik
|
| 83 | + * @author Choi Wang Gyu |
84 | 84 | *
|
85 | 85 | * @since 1.3
|
86 | 86 | */
|
@@ -332,31 +332,25 @@ protected Collection<NewTopic> newTopics() {
|
332 | 332 | Map<String, NewTopic> topicsForRetry = newTopicsMap.entrySet().stream()
|
333 | 333 | .filter(entry -> entry.getValue() instanceof TopicForRetryable)
|
334 | 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 | + |
335 | 340 | for (Entry<String, NewTopic> entry : topicsForRetry.entrySet()) {
|
336 |
| - Iterator<Entry<String, NewTopic>> iterator = newTopicsMap.entrySet().iterator(); |
337 |
| - boolean remove = false; |
338 |
| - while (iterator.hasNext()) { |
339 |
| - Entry<String, NewTopic> nt = iterator.next(); |
340 |
| - // if we have a NewTopic and TopicForRetry with the same name, remove the latter |
341 |
| - if (nt.getValue().name().equals(entry.getValue().name()) |
342 |
| - && !(nt.getValue() instanceof TopicForRetryable)) { |
343 |
| - |
344 |
| - remove = true; |
345 |
| - 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); |
346 | 347 | }
|
347 | 348 | }
|
348 |
| - if (remove) { |
349 |
| - newTopicsMap.remove(entry.getKey()); |
350 |
| - } |
351 | 349 | }
|
352 |
| - Iterator<Entry<String, NewTopic>> iterator = newTopicsMap.entrySet().iterator(); |
353 |
| - while (iterator.hasNext()) { |
354 |
| - Entry<String, NewTopic> next = iterator.next(); |
355 |
| - if (!this.createOrModifyTopic.test(next.getValue())) { |
356 |
| - iterator.remove(); |
357 |
| - } |
358 |
| - } |
359 |
| - 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()); |
360 | 354 | }
|
361 | 355 |
|
362 | 356 | @Override
|
|
0 commit comments