|  | 
| 81 | 81 |  * @author Valentina Armenise | 
| 82 | 82 |  * @author Anders Swanson | 
| 83 | 83 |  * @author Omer Celik | 
|  | 84 | + * @author Choi WangGyu | 
| 84 | 85 |  * | 
| 85 | 86 |  * @since 1.3 | 
| 86 | 87 |  */ | 
| @@ -332,31 +333,25 @@ protected Collection<NewTopic> newTopics() { | 
| 332 | 333 | 		Map<String, NewTopic> topicsForRetry = newTopicsMap.entrySet().stream() | 
| 333 | 334 | 				.filter(entry -> entry.getValue() instanceof TopicForRetryable) | 
| 334 | 335 | 				.collect(Collectors.toMap(Entry::getKey, Entry::getValue)); | 
|  | 336 | +		Map<String, String> topicNameToMapKey = new HashMap<>(); | 
|  | 337 | +		for (Entry<String, NewTopic> entry : newTopicsMap.entrySet()) { | 
|  | 338 | +			topicNameToMapKey.put(entry.getValue().name(), entry.getKey()); | 
|  | 339 | +		} | 
|  | 340 | + | 
| 335 | 341 | 		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; | 
|  | 342 | +			String retryTopicName = entry.getValue().name(); | 
|  | 343 | +			String keyInNewTopicsMap = topicNameToMapKey.get(retryTopicName); | 
|  | 344 | +			if (keyInNewTopicsMap != null) { | 
|  | 345 | +				NewTopic existing = newTopicsMap.get(keyInNewTopicsMap); | 
|  | 346 | +				if (!(existing instanceof TopicForRetryable)) { | 
|  | 347 | +					newTopicsMap.remove(keyInNewTopicsMap); | 
| 346 | 348 | 				} | 
| 347 | 349 | 			} | 
| 348 |  | -			if (remove) { | 
| 349 |  | -				newTopicsMap.remove(entry.getKey()); | 
| 350 |  | -			} | 
| 351 | 350 | 		} | 
| 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()); | 
|  | 351 | +		Map<String, NewTopic> filteredMap = newTopicsMap.entrySet().stream() | 
|  | 352 | +				.filter(entry -> this.createOrModifyTopic.test(entry.getValue())) | 
|  | 353 | +				.collect(Collectors.toMap(Entry::getKey, Entry::getValue)); | 
|  | 354 | +		return new ArrayList<>(filteredMap.values()); | 
| 360 | 355 | 	} | 
| 361 | 356 | 
 | 
| 362 | 357 | 	@Override | 
|  | 
0 commit comments