From 4a857dcddf9004667a0afddc4f66588df1406e27 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Sun, 15 Oct 2023 19:22:33 +0200 Subject: [PATCH] =?UTF-8?q?GH-323=20-=20Move=20off=20of=20Google's=20Suppl?= =?UTF-8?q?iers.memoize(=E2=80=A6).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modulith/core/ApplicationModule.java | 16 +++---- .../core/ArchitecturallyEvidentType.java | 42 +++++++++---------- .../modulith/core/FormatableType.java | 6 +-- .../modulith/core/JavaPackage.java | 6 +-- .../modulith/core/TestUtils.java | 10 +++-- .../modulith/test/ModuleTestExecution.java | 11 +++-- 6 files changed, 46 insertions(+), 45 deletions(-) diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModule.java b/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModule.java index 0f0f7d5b..a7146aae 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModule.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModule.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -38,6 +39,7 @@ import org.springframework.modulith.core.Types.JMoleculesTypes; import org.springframework.modulith.core.Types.SpringTypes; import org.springframework.util.Assert; import org.springframework.util.StringUtils; +import org.springframework.util.function.SingletonSupplier; import com.tngtech.archunit.base.DescribedPredicate; import com.tngtech.archunit.core.domain.Dependency; @@ -48,8 +50,6 @@ import com.tngtech.archunit.core.domain.JavaField; import com.tngtech.archunit.core.domain.JavaMember; import com.tngtech.archunit.core.domain.JavaMethod; import com.tngtech.archunit.core.domain.SourceCodeLocation; -import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier; -import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers; /** * An application module. @@ -89,11 +89,11 @@ public class ApplicationModule { this.namedInterfaces = NamedInterfaces.discoverNamedInterfaces(basePackage); this.useFullyQualifiedModuleNames = useFullyQualifiedModuleNames; - this.springBeans = Suppliers.memoize(() -> filterSpringBeans(basePackage)); - this.aggregateRoots = Suppliers.memoize(() -> findAggregateRoots(basePackage)); - this.valueTypes = Suppliers - .memoize(() -> findArchitecturallyEvidentType(ArchitecturallyEvidentType::isValueObject)); - this.publishedEvents = Suppliers.memoize(() -> findPublishedEvents()); + this.springBeans = SingletonSupplier.of(() -> filterSpringBeans(basePackage)); + this.aggregateRoots = SingletonSupplier.of(() -> findAggregateRoots(basePackage)); + this.valueTypes = SingletonSupplier + .of(() -> findArchitecturallyEvidentType(ArchitecturallyEvidentType::isValueObject)); + this.publishedEvents = SingletonSupplier.of(() -> findPublishedEvents()); } /** @@ -417,7 +417,7 @@ public class ApplicationModule { /** * Returns whether the {@link ApplicationModule} contains the package with the given name, which means the given * package is either the module's base package or a sub package of it. - * + * * @param packageName must not be {@literal null} or empty. * @return whether the {@link ApplicationModule} contains the package with the given name. * @since 1.0.2 diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/core/ArchitecturallyEvidentType.java b/spring-modulith-core/src/main/java/org/springframework/modulith/core/ArchitecturallyEvidentType.java index dbb6d0c8..f139f7f6 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/core/ArchitecturallyEvidentType.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/core/ArchitecturallyEvidentType.java @@ -27,6 +27,7 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Stream; import org.springframework.data.repository.core.RepositoryMetadata; @@ -34,12 +35,10 @@ import org.springframework.data.repository.core.support.AbstractRepositoryMetada import org.springframework.modulith.core.Types.JMoleculesTypes; import org.springframework.modulith.core.Types.SpringDataTypes; import org.springframework.modulith.core.Types.SpringTypes; +import org.springframework.util.function.SingletonSupplier; import com.tngtech.archunit.core.domain.JavaClass; import com.tngtech.archunit.core.domain.JavaMethod; -import com.tngtech.archunit.core.domain.JavaType; -import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier; -import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers; /** * A type that is architecturally relevant, i.e. it fulfills a significant role within the architecture. @@ -488,36 +487,37 @@ public abstract class ArchitecturallyEvidentType { public static DelegatingType of(JavaClass type, List types) { - var isAggregateRoot = Suppliers - .memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isAggregateRoot)); + var isAggregateRoot = SingletonSupplier + .of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isAggregateRoot)); - var isRepository = Suppliers - .memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isRepository)); + var isRepository = SingletonSupplier + .of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isRepository)); - var isEntity = Suppliers - .memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isEntity)); + var isEntity = SingletonSupplier + .of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isEntity)); - var isService = Suppliers - .memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isService)); + var isService = SingletonSupplier + .of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isService)); - var isController = Suppliers - .memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isController)); + var isController = SingletonSupplier + .of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isController)); - var isEventListener = Suppliers - .memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isEventListener)); + var isEventListener = SingletonSupplier + .of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isEventListener)); - var isConfigurationProperties = Suppliers - .memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isConfigurationProperties)); + var isConfigurationProperties = SingletonSupplier + .of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isConfigurationProperties)); - var isInjectable = Suppliers.memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isInjectable)); + var isInjectable = SingletonSupplier.of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isInjectable)); - var isValueObject = Suppliers.memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isValueObject)); + var isValueObject = SingletonSupplier + .of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isValueObject)); - Supplier> referenceTypes = Suppliers.memoize(() -> types.stream() // + Supplier> referenceTypes = SingletonSupplier.of(() -> types.stream() // .flatMap(ArchitecturallyEvidentType::getReferenceTypes) // .toList()); - Supplier> referenceMethods = Suppliers.memoize(() -> types.stream() // + Supplier> referenceMethods = SingletonSupplier.of(() -> types.stream() // .flatMap(ArchitecturallyEvidentType::getReferenceMethods) // .toList()); diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/core/FormatableType.java b/spring-modulith-core/src/main/java/org/springframework/modulith/core/FormatableType.java index 3693c0f5..34605f37 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/core/FormatableType.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/core/FormatableType.java @@ -17,6 +17,7 @@ package org.springframework.modulith.core; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -25,10 +26,9 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; +import org.springframework.util.function.SingletonSupplier; import com.tngtech.archunit.core.domain.JavaClass; -import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier; -import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers; /** * Wrapper around {@link JavaClass} that allows creating additional formatted names. @@ -106,7 +106,7 @@ public class FormatableType { Assert.hasText(type, "Type must not be null or empty!"); this.type = type; - this.abbreviatedName = Suppliers.memoize(() -> { + this.abbreviatedName = SingletonSupplier.of(() -> { String abbreviatedPackage = Stream // .of(ClassUtils.getPackageName(type).split("\\.")) // diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/core/JavaPackage.java b/spring-modulith-core/src/main/java/org/springframework/modulith/core/JavaPackage.java index 0ca9c9fe..d11bfb5e 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/core/JavaPackage.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/core/JavaPackage.java @@ -23,11 +23,13 @@ import java.util.Iterator; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.util.Assert; +import org.springframework.util.function.SingletonSupplier; import com.tngtech.archunit.base.DescribedIterable; import com.tngtech.archunit.base.DescribedPredicate; @@ -35,8 +37,6 @@ import com.tngtech.archunit.core.domain.JavaClass; import com.tngtech.archunit.core.domain.JavaModifier; import com.tngtech.archunit.core.domain.properties.CanBeAnnotated; import com.tngtech.archunit.core.domain.properties.HasModifiers; -import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier; -import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers; /** * An abstraction of a Java package. @@ -67,7 +67,7 @@ public class JavaPackage implements DescribedIterable { this.classes = classes; this.packageClasses = classes.that(resideInAPackage(includeSubPackages ? name.concat("..") : name)); this.name = name; - this.directSubPackages = Suppliers.memoize(() -> packageClasses.stream() // + this.directSubPackages = SingletonSupplier.of(() -> packageClasses.stream() // .map(it -> it.getPackageName()) // .filter(it -> !it.equals(name)) // .map(it -> extractDirectSubPackage(it)) // diff --git a/spring-modulith-core/src/test/java/org/springframework/modulith/core/TestUtils.java b/spring-modulith-core/src/test/java/org/springframework/modulith/core/TestUtils.java index 577de560..b27c3634 100644 --- a/spring-modulith-core/src/test/java/org/springframework/modulith/core/TestUtils.java +++ b/spring-modulith-core/src/test/java/org/springframework/modulith/core/TestUtils.java @@ -17,16 +17,17 @@ package org.springframework.modulith.core; import static com.tngtech.archunit.core.domain.JavaClass.Predicates.*; +import java.util.function.Supplier; + import org.jmolecules.ddd.annotation.AggregateRoot; import org.springframework.data.repository.Repository; import org.springframework.util.Assert; +import org.springframework.util.function.SingletonSupplier; import com.tngtech.archunit.base.DescribedPredicate; import com.tngtech.archunit.core.domain.JavaClass; import com.tngtech.archunit.core.domain.JavaClasses; import com.tngtech.archunit.core.importer.ClassFileImporter; -import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier; -import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers; /** * Utilities for testing. @@ -35,13 +36,14 @@ import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers; */ class TestUtils { - private static Supplier imported = Suppliers.memoize(() -> new ClassFileImporter() // + private static Supplier imported = SingletonSupplier.of(() -> new ClassFileImporter() // .importPackagesOf(ApplicationModules.class, Repository.class, AggregateRoot.class)); private static DescribedPredicate IS_MODULE_TYPE = JavaClass.Predicates .resideInAPackage(ApplicationModules.class.getPackage().getName()); - private static Supplier classes = Suppliers.memoize(() -> Classes.of(imported.get()).that(IS_MODULE_TYPE)); + private static Supplier classes = SingletonSupplier + .of(() -> Classes.of(imported.get()).that(IS_MODULE_TYPE)); /** * Returns all {@link Classes} of this module. diff --git a/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleTestExecution.java b/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleTestExecution.java index 05185ffc..d364cb18 100644 --- a/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleTestExecution.java +++ b/spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleTestExecution.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.function.Supplier; import java.util.stream.Stream; import org.slf4j.Logger; @@ -33,9 +34,7 @@ import org.springframework.modulith.core.ApplicationModule; import org.springframework.modulith.core.ApplicationModules; import org.springframework.modulith.core.JavaPackage; import org.springframework.modulith.test.ApplicationModuleTest.BootstrapMode; - -import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier; -import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers; +import org.springframework.util.function.SingletonSupplier; /** * @author Oliver Drotbohm @@ -66,7 +65,7 @@ public class ModuleTestExecution implements Iterable { this.extraIncludes = getExtraModules(annotation, modules).toList(); - this.basePackages = Suppliers.memoize(() -> { + this.basePackages = SingletonSupplier.of(() -> { var moduleBasePackages = module.getBootstrapBasePackages(modules, bootstrapMode.getDepth()); var sharedBasePackages = modules.getSharedModules().stream().map(it -> it.getBasePackage()); @@ -77,7 +76,7 @@ public class ModuleTestExecution implements Iterable { return Stream.concat(intermediate, sharedBasePackages).distinct().toList(); }); - this.dependencies = Suppliers.memoize(() -> { + this.dependencies = SingletonSupplier.of(() -> { var bootstrapDependencies = module.getBootstrapDependencies(modules, bootstrapMode.getDepth()); @@ -89,7 +88,7 @@ public class ModuleTestExecution implements Iterable { } } - public static java.util.function.Supplier of(Class type) { + public static Supplier of(Class type) { return () -> {