Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APP] Rewrite files under app by java 17 toList #1759

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> {
@Override
public List<Integer> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Short> {
@Override
public List<Short> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
@Override
public List<String> convert(String value) {
return Stream.of(value.split(SEPARATOR)).collect(Collectors.toList());
return Stream.of(value.split(SEPARATOR)).toList();
}
}
5 changes: 2 additions & 3 deletions app/src/main/java/org/astraea/app/web/BalancerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -283,11 +282,11 @@ static Change from(Collection<Replica> before, Collection<Replica> 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<Placement> before, List<Placement> after) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public CompletionStage<Response> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public CompletionStage<Result> 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 =
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/astraea/app/web/TopicHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public CompletionStage<Topics> post(Channel channel) {
.thenApply(ignored -> null)
.toCompletableFuture();
})
.collect(Collectors.toList()))
.toList())
.thenCompose(ignored -> get(topicNames, null, id -> true))
.exceptionally(
ignored ->
Expand Down
6 changes: 2 additions & 4 deletions app/src/test/java/org/astraea/app/EnumInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/test/java/org/astraea/app/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public static List<Class<?>> 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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ private static Set<String> 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()
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions app/src/test/java/org/astraea/app/web/GroupHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 5 additions & 8 deletions app/src/test/java/org/astraea/app/web/RecordHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions app/src/test/java/org/astraea/app/web/RequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,7 +59,7 @@ private static List<Class<?>> requestClasses() {
return TestUtils.getProductionClass().stream()
.filter(Request.class::isAssignableFrom)
.filter(c -> !c.isInterface())
.collect(Collectors.toList());
.toList();
}

public static class RequestClassProvider implements ArgumentsProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions app/src/test/java/org/astraea/app/web/TopicHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down