diff --git a/app/src/main/java/org/astraea/app/argument/PositiveIntegerListField.java b/app/src/main/java/org/astraea/app/argument/PositiveIntegerListField.java index 09dc5943b1..e2038ec71d 100644 --- a/app/src/main/java/org/astraea/app/argument/PositiveIntegerListField.java +++ b/app/src/main/java/org/astraea/app/argument/PositiveIntegerListField.java @@ -17,12 +17,11 @@ package org.astraea.app.argument; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; public class PositiveIntegerListField extends PositiveNumberListField { @Override public List convert(String value) { - return Stream.of(value.split(SEPARATOR)).map(Integer::valueOf).collect(Collectors.toList()); + return Stream.of(value.split(SEPARATOR)).map(Integer::valueOf).toList(); } } diff --git a/app/src/main/java/org/astraea/app/argument/PositiveShortListField.java b/app/src/main/java/org/astraea/app/argument/PositiveShortListField.java index 6baf4f3592..93475db64c 100644 --- a/app/src/main/java/org/astraea/app/argument/PositiveShortListField.java +++ b/app/src/main/java/org/astraea/app/argument/PositiveShortListField.java @@ -17,12 +17,11 @@ package org.astraea.app.argument; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; public class PositiveShortListField extends PositiveNumberListField { @Override public List convert(String value) { - return Stream.of(value.split(SEPARATOR)).map(Short::valueOf).collect(Collectors.toList()); + return Stream.of(value.split(SEPARATOR)).map(Short::valueOf).toList(); } } diff --git a/app/src/main/java/org/astraea/app/argument/StringListField.java b/app/src/main/java/org/astraea/app/argument/StringListField.java index 98b02621a6..731fb423b3 100644 --- a/app/src/main/java/org/astraea/app/argument/StringListField.java +++ b/app/src/main/java/org/astraea/app/argument/StringListField.java @@ -17,12 +17,11 @@ package org.astraea.app.argument; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; public class StringListField extends ListField { @Override public List convert(String value) { - return Stream.of(value.split(SEPARATOR)).collect(Collectors.toList()); + return Stream.of(value.split(SEPARATOR)).toList(); } } diff --git a/app/src/main/java/org/astraea/app/web/BalancerHandler.java b/app/src/main/java/org/astraea/app/web/BalancerHandler.java index 5e0c6038da..84889b19a3 100644 --- a/app/src/main/java/org/astraea/app/web/BalancerHandler.java +++ b/app/src/main/java/org/astraea/app/web/BalancerHandler.java @@ -29,7 +29,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Supplier; -import java.util.stream.Collectors; import org.astraea.common.Configuration; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; @@ -283,11 +282,11 @@ static Change from(Collection before, Collection after) { before.stream() .sorted(Comparator.comparing(Replica::isPreferredLeader).reversed()) .map(r -> new Placement(r, Optional.of(r.size()))) - .collect(Collectors.toList()), + .toList(), after.stream() .sorted(Comparator.comparing(Replica::isPreferredLeader).reversed()) .map(r -> new Placement(r, Optional.empty())) - .collect(Collectors.toList())); + .toList()); } Change(String topic, int partition, List before, List after) { diff --git a/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java b/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java index fee8c4823e..f798c05362 100644 --- a/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java +++ b/app/src/main/java/org/astraea/app/web/ReassignmentHandler.java @@ -111,7 +111,7 @@ public CompletionStage post(Channel channel) { .filter( b -> b.topicPartitions().contains(tp)) .map(NodeInfo::id) - .collect(Collectors.toList()); + .toList(); if (!ids.isEmpty()) return ids; return List.of( availableBrokers diff --git a/app/src/main/java/org/astraea/app/web/SkewedPartitionScenario.java b/app/src/main/java/org/astraea/app/web/SkewedPartitionScenario.java index 7e45b7700a..7fa6eb074c 100644 --- a/app/src/main/java/org/astraea/app/web/SkewedPartitionScenario.java +++ b/app/src/main/java/org/astraea/app/web/SkewedPartitionScenario.java @@ -62,8 +62,7 @@ public CompletionStage apply(Admin admin) { admin.waitPartitionLeaderSynced( Map.of(topicName, partitions), Duration.ofSeconds(4))) .thenCompose(ignored -> admin.brokers()) - .thenApply( - brokers -> brokers.stream().map(NodeInfo::id).sorted().collect(Collectors.toList())) + .thenApply(brokers -> brokers.stream().map(NodeInfo::id).sorted().toList()) .thenCompose( brokerIds -> { var distribution = diff --git a/app/src/main/java/org/astraea/app/web/TopicHandler.java b/app/src/main/java/org/astraea/app/web/TopicHandler.java index 34243bcb17..1e7beec0f2 100644 --- a/app/src/main/java/org/astraea/app/web/TopicHandler.java +++ b/app/src/main/java/org/astraea/app/web/TopicHandler.java @@ -190,7 +190,7 @@ public CompletionStage post(Channel channel) { .thenApply(ignored -> null) .toCompletableFuture(); }) - .collect(Collectors.toList())) + .toList()) .thenCompose(ignored -> get(topicNames, null, id -> true)) .exceptionally( ignored -> diff --git a/app/src/test/java/org/astraea/app/EnumInfoTest.java b/app/src/test/java/org/astraea/app/EnumInfoTest.java index 310ba1fcf1..82bdd57b3f 100644 --- a/app/src/test/java/org/astraea/app/EnumInfoTest.java +++ b/app/src/test/java/org/astraea/app/EnumInfoTest.java @@ -17,7 +17,6 @@ package org.astraea.app; import java.util.Arrays; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.astraea.common.EnumInfo; import org.junit.jupiter.api.Assertions; @@ -104,14 +103,13 @@ void testProductionClass() { Assertions.assertTrue(productionClasses.size() > 100); Assertions.assertTrue( productionClasses.stream().allMatch(x -> x.getPackageName().startsWith("org.astraea"))); - System.out.println( - productionClasses.stream().filter(Class::isEnum).collect(Collectors.toList())); + System.out.println(productionClasses.stream().filter(Class::isEnum).toList()); } @Test void testEnumClassProvider() { var enumClassProvider = new EnumClassProvider(); - var enumCls = enumClassProvider.provideArguments(null).collect(Collectors.toList()); + var enumCls = enumClassProvider.provideArguments(null).toList(); Assertions.assertTrue(enumCls.size() > 0); Assertions.assertTrue(enumCls.stream().map(x -> (Class) x.get()[0]).allMatch(Class::isEnum)); } diff --git a/app/src/test/java/org/astraea/app/TestUtils.java b/app/src/test/java/org/astraea/app/TestUtils.java index 426cf62c52..26074ba091 100644 --- a/app/src/test/java/org/astraea/app/TestUtils.java +++ b/app/src/test/java/org/astraea/app/TestUtils.java @@ -46,14 +46,14 @@ public static List> getProductionClass() { FileUtils.listFiles(mainDir.toFile(), new String[] {"class"}, true).stream() .map(File::toPath) .map(mainDir::relativize) - .collect(Collectors.toList()); + .toList(); var classNames = dirFiles.stream() .map(Path::toString) .map(FilenameUtils::removeExtension) .map(x -> x.replace(File.separatorChar, '.')) - .collect(Collectors.toList()); + .toList(); return classNames.stream() .map(x -> Utils.packException(() -> Class.forName(x))) diff --git a/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java b/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java index 73c9ba3aed..1e4d5d4085 100644 --- a/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java @@ -193,10 +193,7 @@ private static Set createAndProduceTopic( .join(); if (skewed) { Utils.sleep(Duration.ofSeconds(1)); - var placement = - service.dataFolders().keySet().stream() - .limit(replicas) - .collect(Collectors.toUnmodifiableList()); + var placement = service.dataFolders().keySet().stream().limit(replicas).toList(); admin .moveToBrokers( admin.topicPartitions(Set.of(topic)).toCompletableFuture().join().stream() @@ -955,13 +952,13 @@ void testChangeOrder() { .mapToObj(partition -> Map.entry(ThreadLocalRandom.current().nextInt(), partition)) .sorted(Map.Entry.comparingByKey()) .map(Map.Entry::getValue) - .collect(Collectors.toUnmodifiableList()); + .toList(); var destPlacement = IntStream.range(0, 10) .mapToObj(partition -> Map.entry(ThreadLocalRandom.current().nextInt(), partition)) .sorted(Map.Entry.comparingByKey()) .map(Map.Entry::getValue) - .collect(Collectors.toUnmodifiableList()); + .toList(); var base = ClusterInfo.builder() .addNode(Set.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) diff --git a/app/src/test/java/org/astraea/app/web/GroupHandlerTest.java b/app/src/test/java/org/astraea/app/web/GroupHandlerTest.java index 5bc4c86639..de375d0c2b 100644 --- a/app/src/test/java/org/astraea/app/web/GroupHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/GroupHandlerTest.java @@ -22,7 +22,6 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletionException; -import java.util.stream.Collectors; import java.util.stream.IntStream; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; @@ -237,8 +236,7 @@ void testDeleteGroup() { try (var admin = Admin.of(SERVICE.bootstrapServers())) { var handler = new GroupHandler(admin); - var groupIds = - IntStream.range(0, 3).mapToObj(x -> Utils.randomString(10)).collect(Collectors.toList()); + var groupIds = IntStream.range(0, 3).mapToObj(x -> Utils.randomString(10)).toList(); groupIds.forEach( groupId -> { try (var consumer = diff --git a/app/src/test/java/org/astraea/app/web/ProducerHandlerTest.java b/app/src/test/java/org/astraea/app/web/ProducerHandlerTest.java index 631b044733..ee3ed3e0a0 100644 --- a/app/src/test/java/org/astraea/app/web/ProducerHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/ProducerHandlerTest.java @@ -55,10 +55,7 @@ void testListProducers() { handler.get(Channel.EMPTY).toCompletableFuture().join()); Assertions.assertNotEquals(0, result.partitions.size()); - var partitions = - result.partitions.stream() - .filter(t -> t.topic.equals(topicName)) - .collect(Collectors.toUnmodifiableList()); + var partitions = result.partitions.stream().filter(t -> t.topic.equals(topicName)).toList(); Assertions.assertEquals(1, partitions.size()); Assertions.assertEquals(topicName, partitions.iterator().next().topic); Assertions.assertEquals(0, partitions.iterator().next().partition); diff --git a/app/src/test/java/org/astraea/app/web/RecordHandlerTest.java b/app/src/test/java/org/astraea/app/web/RecordHandlerTest.java index ed44664d15..7673b035e1 100644 --- a/app/src/test/java/org/astraea/app/web/RecordHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/RecordHandlerTest.java @@ -38,7 +38,6 @@ import java.util.Map; import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; import org.astraea.app.web.RecordHandler.Metadata; @@ -150,8 +149,7 @@ void testPostRawString() { .keyDeserializer(Deserializer.STRING) .valueDeserializer(Deserializer.STRING) .build()) { - var records = - consumer.poll(Duration.ofSeconds(5)).stream().collect(Collectors.toUnmodifiableList()); + var records = consumer.poll(Duration.ofSeconds(5)).stream().toList(); Assertions.assertEquals(1, records.size()); Assertions.assertEquals(0, records.get(0).partition()); Assertions.assertEquals("abc", records.get(0).key()); @@ -209,8 +207,7 @@ void testPost(boolean isTransaction) { .keyDeserializer(Deserializer.STRING) .valueDeserializer(Deserializer.INTEGER) .build()) { - var records = - consumer.poll(Duration.ofSeconds(10)).stream().collect(Collectors.toUnmodifiableList()); + var records = consumer.poll(Duration.ofSeconds(10)).stream().toList(); Assertions.assertEquals(2, records.size()); var record = records.get(0); @@ -820,7 +817,7 @@ void testDelete() { var records = Stream.of(0, 0, 1, 1, 1, 2, 2, 2, 2) .map(x -> Record.builder().topic(topicName).partition(x).value(new byte[100]).build()) - .collect(Collectors.toList()); + .toList(); producer.send(records); producer.flush(); @@ -904,7 +901,7 @@ void testDeleteOffset() { var records = Stream.of(0, 0, 1, 1, 1, 2, 2, 2, 2) .map(x -> Record.builder().topic(topicName).partition(x).value(new byte[100]).build()) - .collect(Collectors.toList()); + .toList(); producer.send(records); producer.flush(); @@ -961,7 +958,7 @@ void testDeletePartition() { var records = Stream.of(0, 0, 1, 1, 1, 2, 2, 2, 2) .map(x -> Record.builder().topic(topicName).partition(x).value(new byte[100]).build()) - .collect(Collectors.toList()); + .toList(); producer.send(records); producer.flush(); diff --git a/app/src/test/java/org/astraea/app/web/RequestTest.java b/app/src/test/java/org/astraea/app/web/RequestTest.java index 0aa3fd8b0e..74457b3e26 100644 --- a/app/src/test/java/org/astraea/app/web/RequestTest.java +++ b/app/src/test/java/org/astraea/app/web/RequestTest.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.astraea.app.TestUtils; import org.astraea.app.web.RecordHandler.PostRecord; @@ -60,7 +59,7 @@ private static List> requestClasses() { return TestUtils.getProductionClass().stream() .filter(Request.class::isAssignableFrom) .filter(c -> !c.isInterface()) - .collect(Collectors.toList()); + .toList(); } public static class RequestClassProvider implements ArgumentsProvider { diff --git a/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java b/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java index c00a850fa5..35ebc92214 100644 --- a/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/ThrottleHandlerTest.java @@ -176,9 +176,7 @@ void testThrottleSomeLogs() { handler.get(Channel.EMPTY).toCompletableFuture().join()); var topic = - throttleSetting.topics.stream() - .filter(t -> t.name.get().equals(topicName)) - .collect(Collectors.toList()); + throttleSetting.topics.stream().filter(t -> t.name.get().equals(topicName)).toList(); Assertions.assertEquals(2, topic.size()); var leader = @@ -228,9 +226,7 @@ void testThrottleEveryLog() { ThrottleHandler.ThrottleSetting.class, handler.get(Channel.EMPTY).toCompletableFuture().join()); var topic = - throttleSetting.topics.stream() - .filter(t -> t.name.get().equals(topicName)) - .collect(Collectors.toList()); + throttleSetting.topics.stream().filter(t -> t.name.get().equals(topicName)).toList(); Assertions.assertEquals(9, topic.size()); IntStream.range(0, 3) diff --git a/app/src/test/java/org/astraea/app/web/TopicHandlerForProbabilityTest.java b/app/src/test/java/org/astraea/app/web/TopicHandlerForProbabilityTest.java index 0617fa3757..71ca06ce5a 100644 --- a/app/src/test/java/org/astraea/app/web/TopicHandlerForProbabilityTest.java +++ b/app/src/test/java/org/astraea/app/web/TopicHandlerForProbabilityTest.java @@ -69,8 +69,7 @@ void testCreateTopicByProbability() { .partitions.stream() .flatMap(p -> p.replicas.stream()) .collect(Collectors.groupingBy(r -> r.broker)); - var numberOfReplicas = - groupByBroker.values().stream().map(List::size).collect(Collectors.toList()); + var numberOfReplicas = groupByBroker.values().stream().map(List::size).toList(); replica0 += numberOfReplicas.get(0); replica1 += numberOfReplicas.get(1); replica2 += numberOfReplicas.size() == 3 ? numberOfReplicas.get(2) : 0; diff --git a/app/src/test/java/org/astraea/app/web/TopicHandlerTest.java b/app/src/test/java/org/astraea/app/web/TopicHandlerTest.java index 6aa023deff..972394489e 100644 --- a/app/src/test/java/org/astraea/app/web/TopicHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/TopicHandlerTest.java @@ -322,8 +322,7 @@ void testCreateTopicWithReplicas() { @Test void testDeleteTopic() { - var topicNames = - IntStream.range(0, 3).mapToObj(x -> Utils.randomString(10)).collect(Collectors.toList()); + var topicNames = IntStream.range(0, 3).mapToObj(x -> Utils.randomString(10)).toList(); try (var admin = Admin.of(SERVICE.bootstrapServers())) { var handler = new TopicHandler(admin); for (var name : topicNames)