GH-69 - Switch to Stream.toList().

This commit is contained in:
Oliver Drotbohm
2022-11-11 18:38:53 +01:00
parent d96263fe30
commit 55b16857f3
16 changed files with 27 additions and 34 deletions

View File

@@ -20,7 +20,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.modulith.ApplicationModule;
@@ -125,7 +124,7 @@ interface ApplicationModuleInformation {
return annotation //
.map(it -> Arrays.stream(it.allowedDependencies())) //
.orElse(Stream.empty()) //
.collect(Collectors.toList());
.toList();
}
}
}

View File

@@ -102,7 +102,7 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
this.rootPackages = packages.stream() //
.map(it -> JavaPackage.of(classes, it).toSingle()) //
.collect(Collectors.toList());
.toList();
this.sharedModules = Collections.emptySet();
}

View File

@@ -77,7 +77,7 @@ class Classes implements DescribedIterable<JavaClass> {
static Classes of(JavaClasses classes) {
return new Classes(StreamSupport.stream(classes.spliterator(), false) //
.collect(Collectors.toList()));
.toList());
}
/**

View File

@@ -18,12 +18,10 @@ package org.springframework.modulith.model;
import lombok.Value;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.util.Assert;
import com.tngtech.archunit.core.domain.JavaAccess;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaModifier;
@@ -54,18 +52,18 @@ public class EventType {
this.type = type;
Stream<JavaAccess<?>> factoryMethodCalls = type.getMethods().stream()
var factoryMethodCalls = type.getMethods().stream()
.filter(method -> method.getModifiers().contains(JavaModifier.STATIC))
.filter(method -> method.getRawReturnType().equals(type))
.flatMap(method -> method.getCallsOfSelf().stream());
Stream<JavaAccess<?>> constructorCalls = type.getConstructors().stream()
var constructorCalls = type.getConstructors().stream()
.flatMap(constructor -> constructor.getCallsOfSelf().stream());
this.sources = Stream.concat(constructorCalls, factoryMethodCalls)
.filter(call -> !call.getOriginOwner().equals(type))
.map(JavaAccessSource::new)
.collect(Collectors.toList());
.<Source> map(JavaAccessSource::new)
.toList();
}
public boolean hasSources() {

View File

@@ -22,7 +22,6 @@ import lombok.RequiredArgsConstructor;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.util.Assert;
@@ -56,7 +55,7 @@ public abstract class NamedInterface implements Iterable<JavaClass> {
return Arrays.stream(name) //
.map(it -> new PackageBasedNamedInterface(it, javaPackage)) //
.collect(Collectors.toList());
.toList();
}
public static TypeBasedNamedInterface of(String name, Classes classes, JavaPackage basePackage) {

View File

@@ -84,7 +84,7 @@ public class NamedInterfaces implements Iterable<NamedInterface> {
return mappings.entrySet().stream() //
.map(entry -> NamedInterface.of(entry.getKey(), Classes.of(entry.getValue()), basePackage)) //
.collect(Collectors.toList());
.toList();
}
private NamedInterfaces and(NamedInterface namedInterface) {

View File

@@ -21,7 +21,6 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.stream.Collectors;
import com.tngtech.archunit.core.domain.JavaClass;
@@ -65,7 +64,7 @@ public class SpringBean {
return type.getRawInterfaces().stream() //
.filter(module::contains) //
.collect(Collectors.toList());
.toList();
}
public boolean isAnnotatedWith(Class<?> type) {

View File

@@ -62,7 +62,7 @@ class ConfigurationProperties implements Iterable<ConfigurationProperty> {
this.properties = Arrays.stream(resources)
.flatMap(ConfigurationProperties::parseProperties)
.collect(Collectors.toList());
.toList();
} catch (IOException e) {
throw new RuntimeException(e);
@@ -81,7 +81,7 @@ class ConfigurationProperties implements Iterable<ConfigurationProperty> {
return properties.stream()
.flatMap(it -> getModuleProperty(module, it))
.collect(Collectors.toList());
.toList();
}
/*

View File

@@ -822,7 +822,7 @@ public class Documenter {
.filter(it -> !hideInternals || it.isApiBean())
.filter(it -> !alreadyMapped.contains(it))
.filter(filter::matches)
.collect(Collectors.toList());
.toList();
}
@Value(staticConstructor = "of")

View File

@@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.beans.factory.SmartInitializingSingleton;
@@ -165,7 +164,7 @@ public class PersistentApplicationEventMulticaster extends AbstractApplicationEv
.filter(TransactionalApplicationListener.class::isInstance)
.map(TransactionalApplicationListener.class::cast)
.sorted(AnnotationAwareOrderComparator.INSTANCE)
.collect(Collectors.toList());
.toList();
}
private TransactionalEventListeners(
@@ -185,7 +184,7 @@ public class PersistentApplicationEventMulticaster extends AbstractApplicationEv
List<TransactionalApplicationListener<ApplicationEvent>> collect = listeners.stream()
.filter(it -> it.getTransactionPhase().equals(phase))
.collect(Collectors.toList());
.toList();
return new TransactionalEventListeners(collect);
}

View File

@@ -24,7 +24,6 @@ import lombok.RequiredArgsConstructor;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
@@ -85,16 +84,15 @@ class MongoDbEventPublicationRepository implements EventPublicationRepository {
var query = query(where("completionDate").isNull());
return mongoTemplate.find(query, MongoDbEventPublication.class).stream() //
.map(this::documentToDomain) //
.collect(Collectors.toList());
.<EventPublication> map(this::documentToDomain) //
.toList();
}
@Override
public Optional<EventPublication> findIncompletePublicationsByEventAndTargetIdentifier(
Object event, PublicationTargetIdentifier targetIdentifier) {
var documents = findDocumentsByEventAndTargetIdentifierAndCompletionDateNull( //
event, targetIdentifier);
var documents = findDocumentsByEventAndTargetIdentifierAndCompletionDateNull(event, targetIdentifier);
var results = documents
.stream() //
.map(this::documentToDomain) //
@@ -113,7 +111,8 @@ class MongoDbEventPublicationRepository implements EventPublicationRepository {
Object event, PublicationTargetIdentifier targetIdentifier) {
// we need to enforce writing of the type information
var eventAsMongoType = mongoTemplate.getConverter().convertToMongoType(event, TypeInformation.of(Object.class));
var eventAsMongoType = mongoTemplate.getConverter().convertToMongoType(event, TypeInformation.OBJECT);
var query = query(
where("event").is(eventAsMongoType) //
.and("listenerId").is(targetIdentifier.getValue()) //

View File

@@ -147,7 +147,7 @@ class ModulesIntegrationTest {
assertThat(fromPackage.stream().map(ApplicationModule::getName)) //
.containsExactlyInAnyOrderElementsOf(
modules.stream().map(ApplicationModule::getName).collect(Collectors.toList()));
modules.stream().map(ApplicationModule::getName).toList());
}
private static void verifyNamedInterfaces(NamedInterfaces interfaces, String name, Class<?>... types) {

View File

@@ -130,7 +130,7 @@ public class MomentsProperties {
return new ShiftedQuarters(Arrays.stream(Quarter.values())
.map(it -> ShiftedQuarter.of(it, shift))
.collect(Collectors.toList()));
.toList());
}
}
}

View File

@@ -94,7 +94,7 @@ class DefaultPublishedEvents implements PublishedEvents, ApplicationListener<App
private final List<T> events;
private static <T> SimpleTypedPublishedEvents<T> of(Stream<T> stream) {
return new SimpleTypedPublishedEvents<>(stream.collect(Collectors.toList()));
return new SimpleTypedPublishedEvents<>(stream.toList());
}
/*

View File

@@ -63,7 +63,7 @@ class ModuleTestAutoConfiguration {
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
ModuleTestExecution execution = ((BeanFactory) registry).getBean(ModuleTestExecution.class);
List<String> basePackages = execution.getBasePackages().collect(Collectors.toList());
List<String> basePackages = execution.getBasePackages().toList();
LOG.info("Re-configuring auto-configuration and entity scan packages to: {}.",
StringUtils.collectionToDelimitedString(basePackages, ", "));

View File

@@ -68,7 +68,7 @@ public class ModuleTestExecution implements Iterable<ApplicationModule> {
this.bootstrapMode = annotation.mode();
this.module = module;
this.extraIncludes = getExtraModules(annotation, modules).collect(Collectors.toList());
this.extraIncludes = getExtraModules(annotation, modules).toList();
this.basePackages = Suppliers.memoize(() -> {
@@ -78,13 +78,13 @@ public class ModuleTestExecution implements Iterable<ApplicationModule> {
Stream<JavaPackage> intermediate = Stream.concat(moduleBasePackages, extraPackages);
return Stream.concat(intermediate, sharedBasePackages).distinct().collect(Collectors.toList());
return Stream.concat(intermediate, sharedBasePackages).distinct().toList();
});
this.dependencies = Suppliers.memoize(() -> {
Stream<ApplicationModule> bootstrapDependencies = module.getBootstrapDependencies(modules, bootstrapMode.getDepth());
return Stream.concat(bootstrapDependencies, extraIncludes.stream()).collect(Collectors.toList());
return Stream.concat(bootstrapDependencies, extraIncludes.stream()).toList();
});
if (annotation.verifyAutomatically()) {