Skip to content

Commit e0dadd5

Browse files
committed
Refactor newTopics filtering with removeIf
Replace manual Iterator loop with Collection.removeIf() to improve code readability and maintainability. The original implementation used a while loop with Iterator to remove entries that don't match the createOrModifyTopic predicate. While this worked, it required more boilerplate code and was less expressive. The new implementation uses the removeIf method introduced in Java 8, which directly expresses the filtering operation in a single line. This reduces method complexity and makes the code more idiomatic. Signed-off-by: Choi Wang Gyu <[email protected]>
1 parent c1a7ce9 commit e0dadd5

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

spring-kafka/src/main/java/org/springframework/kafka/core/KafkaAdmin.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,8 @@ protected Collection<NewTopic> newTopics() {
347347
}
348348
}
349349
}
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());
350+
newTopicsMap.entrySet().removeIf(entry -> !this.createOrModifyTopic.test(entry.getValue()));
351+
return new ArrayList<>(newTopicsMap.values());
354352
}
355353

356354
@Override

0 commit comments

Comments
 (0)