Use Stream.toList()

See gh-36167
pull/37018/head
Johnny Lim 1 year ago committed by Andy Wilkinson
parent bdead8d0e3
commit 0fa58c04e7

@ -21,7 +21,6 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.tngtech.archunit.base.DescribedPredicate; import com.tngtech.archunit.base.DescribedPredicate;
@ -70,7 +69,7 @@ public abstract class ArchitectureCheck extends DefaultTask {
@TaskAction @TaskAction
void checkArchitecture() throws IOException { void checkArchitecture() throws IOException {
JavaClasses javaClasses = new ClassFileImporter() JavaClasses javaClasses = new ClassFileImporter()
.importPaths(this.classes.getFiles().stream().map(File::toPath).collect(Collectors.toList())); .importPaths(this.classes.getFiles().stream().map(File::toPath).toList());
List<EvaluationResult> violations = Stream.of(allPackagesShouldBeFreeOfTangles(), List<EvaluationResult> violations = Stream.of(allPackagesShouldBeFreeOfTangles(),
allBeanPostProcessorBeanMethodsShouldBeStaticAndHaveParametersThatWillNotCausePrematureInitialization(), allBeanPostProcessorBeanMethodsShouldBeStaticAndHaveParametersThatWillNotCausePrematureInitialization(),
allBeanFactoryPostProcessorBeanMethodsShouldBeStaticAndHaveNoParameters(), allBeanFactoryPostProcessorBeanMethodsShouldBeStaticAndHaveNoParameters(),
@ -78,7 +77,7 @@ public abstract class ArchitectureCheck extends DefaultTask {
noClassesShouldConfigureDefaultStepVerifierTimeout()) noClassesShouldConfigureDefaultStepVerifierTimeout())
.map((rule) -> rule.evaluate(javaClasses)) .map((rule) -> rule.evaluate(javaClasses))
.filter(EvaluationResult::hasViolation) .filter(EvaluationResult::hasViolation)
.collect(Collectors.toList()); .toList();
File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile(); File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile();
outputFile.getParentFile().mkdirs(); outputFile.getParentFile().mkdirs();
if (!violations.isEmpty()) { if (!violations.isEmpty()) {

@ -103,7 +103,7 @@ class StandardLibraryUpdateResolver implements LibraryUpdateResolver {
.flatMap(SortedSet::stream) .flatMap(SortedSet::stream)
.distinct() .distinct()
.filter((dependencyVersion) -> isPermitted(dependencyVersion, library.getProhibitedVersions())) .filter((dependencyVersion) -> isPermitted(dependencyVersion, library.getProhibitedVersions()))
.collect(Collectors.toList()); .toList();
if (allVersions.isEmpty()) { if (allVersions.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }

@ -50,7 +50,7 @@ class ArtifactCollector {
Collection<DeployableArtifact> collectArtifacts(Path root) { Collection<DeployableArtifact> collectArtifacts(Path root) {
try (Stream<Path> artifacts = Files.walk(root)) { try (Stream<Path> artifacts = Files.walk(root)) {
return artifacts.filter(Files::isRegularFile).filter(this.excludeFilter) return artifacts.filter(Files::isRegularFile).filter(this.excludeFilter)
.map((artifact) -> deployableArtifact(artifact, root)).collect(Collectors.toList()); .map((artifact) -> deployableArtifact(artifact, root)).toList();
} }
catch (IOException ex) { catch (IOException ex) {
throw new RuntimeException("Could not read artifacts from '" + root + "'"); throw new RuntimeException("Could not read artifacts from '" + root + "'");

@ -208,7 +208,7 @@ public class SonatypeService {
List<String> failureMessages = Stream.of(activities).flatMap((activity) -> activity.events.stream()) List<String> failureMessages = Stream.of(activities).flatMap((activity) -> activity.events.stream())
.filter((event) -> event.severity > 0).flatMap((event) -> event.properties.stream()) .filter((event) -> event.severity > 0).flatMap((event) -> event.properties.stream())
.filter((property) -> "failureMessage".equals(property.name)) .filter((property) -> "failureMessage".equals(property.name))
.map((property) -> " " + property.value).collect(Collectors.toList()); .map((property) -> " " + property.value).toList();
if (failureMessages.isEmpty()) { if (failureMessages.isEmpty()) {
logger.error("Close failed for unknown reasons"); logger.error("Close failed for unknown reasons");
} }

@ -21,7 +21,6 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.flywaydb.core.Flyway; import org.flywaydb.core.Flyway;
@ -116,7 +115,7 @@ public class FlywayEndpoint {
private final List<FlywayMigrationDescriptor> migrations; private final List<FlywayMigrationDescriptor> migrations;
private FlywayDescriptor(MigrationInfo[] migrations) { private FlywayDescriptor(MigrationInfo[] migrations) {
this.migrations = Stream.of(migrations).map(FlywayMigrationDescriptor::new).collect(Collectors.toList()); this.migrations = Stream.of(migrations).map(FlywayMigrationDescriptor::new).toList();
} }
public FlywayDescriptor(List<FlywayMigrationDescriptor> migrations) { public FlywayDescriptor(List<FlywayMigrationDescriptor> migrations) {

@ -84,10 +84,10 @@ class ResolvedDependencies {
} }
void resolvedArtifacts(Provider<Set<ResolvedArtifactResult>> resolvedArtifacts) { void resolvedArtifacts(Provider<Set<ResolvedArtifactResult>> resolvedArtifacts) {
this.artifactFiles.addAll(resolvedArtifacts this.artifactFiles.addAll(
.map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getFile).collect(Collectors.toList()))); resolvedArtifacts.map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getFile).toList()));
this.artifactIds.addAll(resolvedArtifacts this.artifactIds.addAll(
.map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getId).collect(Collectors.toList()))); resolvedArtifacts.map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getId).toList()));
} }
DependencyDescriptor find(File file) { DependencyDescriptor find(File file) {

@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty; import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository; import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository;
@ -82,9 +81,7 @@ class PropertiesMigrationReporter {
private PropertySource<?> mapPropertiesWithReplacement(PropertiesMigrationReport report, String name, private PropertySource<?> mapPropertiesWithReplacement(PropertiesMigrationReport report, String name,
List<PropertyMigration> properties) { List<PropertyMigration> properties) {
report.add(name, properties); report.add(name, properties);
List<PropertyMigration> renamed = properties.stream() List<PropertyMigration> renamed = properties.stream().filter(PropertyMigration::isCompatibleType).toList();
.filter(PropertyMigration::isCompatibleType)
.collect(Collectors.toList());
if (renamed.isEmpty()) { if (renamed.isEmpty()) {
return null; return null;
} }
@ -118,10 +115,7 @@ class PropertiesMigrationReporter {
private Map<String, List<PropertyMigration>> getMatchingProperties( private Map<String, List<PropertyMigration>> getMatchingProperties(
Predicate<ConfigurationMetadataProperty> filter) { Predicate<ConfigurationMetadataProperty> filter) {
MultiValueMap<String, PropertyMigration> result = new LinkedMultiValueMap<>(); MultiValueMap<String, PropertyMigration> result = new LinkedMultiValueMap<>();
List<ConfigurationMetadataProperty> candidates = this.allProperties.values() List<ConfigurationMetadataProperty> candidates = this.allProperties.values().stream().filter(filter).toList();
.stream()
.filter(filter)
.collect(Collectors.toList());
getPropertySourcesAsMap().forEach((propertySourceName, propertySource) -> candidates.forEach((metadata) -> { getPropertySourcesAsMap().forEach((propertySourceName, propertySource) -> candidates.forEach((metadata) -> {
ConfigurationPropertyName metadataName = ConfigurationPropertyName.isValid(metadata.getId()) ConfigurationPropertyName metadataName = ConfigurationPropertyName.isValid(metadata.getId())
? ConfigurationPropertyName.of(metadata.getId()) ? ConfigurationPropertyName.of(metadata.getId())

@ -33,7 +33,6 @@ import java.util.Set;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
@ -97,7 +96,7 @@ final class ModifiedClassPathClassLoader extends URLClassLoader {
candidates.addAll(getAnnotatedElements(arguments.toArray())); candidates.addAll(getAnnotatedElements(arguments.toArray()));
List<AnnotatedElement> annotatedElements = candidates.stream() List<AnnotatedElement> annotatedElements = candidates.stream()
.filter(ModifiedClassPathClassLoader::hasAnnotation) .filter(ModifiedClassPathClassLoader::hasAnnotation)
.collect(Collectors.toList()); .toList();
if (annotatedElements.isEmpty()) { if (annotatedElements.isEmpty()) {
return null; return null;
} }

Loading…
Cancel
Save