Skip to content

Commit 4a857dc

Browse files
committed
GH-323 - Move off of Google's Suppliers.memoize(…).
1 parent cb6d71b commit 4a857dc

File tree

6 files changed

+46
-45
lines changed

6 files changed

+46
-45
lines changed

spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModule.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Objects;
3131
import java.util.Optional;
3232
import java.util.function.Predicate;
33+
import java.util.function.Supplier;
3334
import java.util.stream.Collectors;
3435
import java.util.stream.Stream;
3536

@@ -38,6 +39,7 @@
3839
import org.springframework.modulith.core.Types.SpringTypes;
3940
import org.springframework.util.Assert;
4041
import org.springframework.util.StringUtils;
42+
import org.springframework.util.function.SingletonSupplier;
4143

4244
import com.tngtech.archunit.base.DescribedPredicate;
4345
import com.tngtech.archunit.core.domain.Dependency;
@@ -48,8 +50,6 @@
4850
import com.tngtech.archunit.core.domain.JavaMember;
4951
import com.tngtech.archunit.core.domain.JavaMethod;
5052
import com.tngtech.archunit.core.domain.SourceCodeLocation;
51-
import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier;
52-
import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers;
5353

5454
/**
5555
* An application module.
@@ -89,11 +89,11 @@ public class ApplicationModule {
8989
this.namedInterfaces = NamedInterfaces.discoverNamedInterfaces(basePackage);
9090
this.useFullyQualifiedModuleNames = useFullyQualifiedModuleNames;
9191

92-
this.springBeans = Suppliers.memoize(() -> filterSpringBeans(basePackage));
93-
this.aggregateRoots = Suppliers.memoize(() -> findAggregateRoots(basePackage));
94-
this.valueTypes = Suppliers
95-
.memoize(() -> findArchitecturallyEvidentType(ArchitecturallyEvidentType::isValueObject));
96-
this.publishedEvents = Suppliers.memoize(() -> findPublishedEvents());
92+
this.springBeans = SingletonSupplier.of(() -> filterSpringBeans(basePackage));
93+
this.aggregateRoots = SingletonSupplier.of(() -> findAggregateRoots(basePackage));
94+
this.valueTypes = SingletonSupplier
95+
.of(() -> findArchitecturallyEvidentType(ArchitecturallyEvidentType::isValueObject));
96+
this.publishedEvents = SingletonSupplier.of(() -> findPublishedEvents());
9797
}
9898

9999
/**
@@ -417,7 +417,7 @@ boolean contains(String candidate) {
417417
/**
418418
* Returns whether the {@link ApplicationModule} contains the package with the given name, which means the given
419419
* package is either the module's base package or a sub package of it.
420-
*
420+
*
421421
* @param packageName must not be {@literal null} or empty.
422422
* @return whether the {@link ApplicationModule} contains the package with the given name.
423423
* @since 1.0.2

spring-modulith-core/src/main/java/org/springframework/modulith/core/ArchitecturallyEvidentType.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@
2727
import java.util.Set;
2828
import java.util.concurrent.ConcurrentHashMap;
2929
import java.util.function.Predicate;
30+
import java.util.function.Supplier;
3031
import java.util.stream.Stream;
3132

3233
import org.springframework.data.repository.core.RepositoryMetadata;
3334
import org.springframework.data.repository.core.support.AbstractRepositoryMetadata;
3435
import org.springframework.modulith.core.Types.JMoleculesTypes;
3536
import org.springframework.modulith.core.Types.SpringDataTypes;
3637
import org.springframework.modulith.core.Types.SpringTypes;
38+
import org.springframework.util.function.SingletonSupplier;
3739

3840
import com.tngtech.archunit.core.domain.JavaClass;
3941
import com.tngtech.archunit.core.domain.JavaMethod;
40-
import com.tngtech.archunit.core.domain.JavaType;
41-
import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier;
42-
import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers;
4342

4443
/**
4544
* A type that is architecturally relevant, i.e. it fulfills a significant role within the architecture.
@@ -488,36 +487,37 @@ static class DelegatingType extends ArchitecturallyEvidentType {
488487

489488
public static DelegatingType of(JavaClass type, List<ArchitecturallyEvidentType> types) {
490489

491-
var isAggregateRoot = Suppliers
492-
.memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isAggregateRoot));
490+
var isAggregateRoot = SingletonSupplier
491+
.of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isAggregateRoot));
493492

494-
var isRepository = Suppliers
495-
.memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isRepository));
493+
var isRepository = SingletonSupplier
494+
.of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isRepository));
496495

497-
var isEntity = Suppliers
498-
.memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isEntity));
496+
var isEntity = SingletonSupplier
497+
.of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isEntity));
499498

500-
var isService = Suppliers
501-
.memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isService));
499+
var isService = SingletonSupplier
500+
.of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isService));
502501

503-
var isController = Suppliers
504-
.memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isController));
502+
var isController = SingletonSupplier
503+
.of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isController));
505504

506-
var isEventListener = Suppliers
507-
.memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isEventListener));
505+
var isEventListener = SingletonSupplier
506+
.of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isEventListener));
508507

509-
var isConfigurationProperties = Suppliers
510-
.memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isConfigurationProperties));
508+
var isConfigurationProperties = SingletonSupplier
509+
.of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isConfigurationProperties));
511510

512-
var isInjectable = Suppliers.memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isInjectable));
511+
var isInjectable = SingletonSupplier.of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isInjectable));
513512

514-
var isValueObject = Suppliers.memoize(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isValueObject));
513+
var isValueObject = SingletonSupplier
514+
.of(() -> types.stream().anyMatch(ArchitecturallyEvidentType::isValueObject));
515515

516-
Supplier<Collection<JavaClass>> referenceTypes = Suppliers.memoize(() -> types.stream() //
516+
Supplier<Collection<JavaClass>> referenceTypes = SingletonSupplier.of(() -> types.stream() //
517517
.flatMap(ArchitecturallyEvidentType::getReferenceTypes) //
518518
.toList());
519519

520-
Supplier<Collection<ReferenceMethod>> referenceMethods = Suppliers.memoize(() -> types.stream() //
520+
Supplier<Collection<ReferenceMethod>> referenceMethods = SingletonSupplier.of(() -> types.stream() //
521521
.flatMap(ArchitecturallyEvidentType::getReferenceMethods) //
522522
.toList());
523523

spring-modulith-core/src/main/java/org/springframework/modulith/core/FormatableType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.Map;
1919
import java.util.concurrent.ConcurrentHashMap;
20+
import java.util.function.Supplier;
2021
import java.util.stream.Collectors;
2122
import java.util.stream.Stream;
2223
import java.util.stream.StreamSupport;
@@ -25,10 +26,9 @@
2526
import org.springframework.util.Assert;
2627
import org.springframework.util.ClassUtils;
2728
import org.springframework.util.StringUtils;
29+
import org.springframework.util.function.SingletonSupplier;
2830

2931
import com.tngtech.archunit.core.domain.JavaClass;
30-
import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier;
31-
import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers;
3232

3333
/**
3434
* Wrapper around {@link JavaClass} that allows creating additional formatted names.
@@ -106,7 +106,7 @@ private FormatableType(String type) {
106106
Assert.hasText(type, "Type must not be null or empty!");
107107

108108
this.type = type;
109-
this.abbreviatedName = Suppliers.memoize(() -> {
109+
this.abbreviatedName = SingletonSupplier.of(() -> {
110110

111111
String abbreviatedPackage = Stream //
112112
.of(ClassUtils.getPackageName(type).split("\\.")) //

spring-modulith-core/src/main/java/org/springframework/modulith/core/JavaPackage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
import java.util.Objects;
2424
import java.util.Optional;
2525
import java.util.Set;
26+
import java.util.function.Supplier;
2627
import java.util.stream.Collectors;
2728
import java.util.stream.Stream;
2829

2930
import org.springframework.core.annotation.AnnotatedElementUtils;
3031
import org.springframework.util.Assert;
32+
import org.springframework.util.function.SingletonSupplier;
3133

3234
import com.tngtech.archunit.base.DescribedIterable;
3335
import com.tngtech.archunit.base.DescribedPredicate;
3436
import com.tngtech.archunit.core.domain.JavaClass;
3537
import com.tngtech.archunit.core.domain.JavaModifier;
3638
import com.tngtech.archunit.core.domain.properties.CanBeAnnotated;
3739
import com.tngtech.archunit.core.domain.properties.HasModifiers;
38-
import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier;
39-
import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers;
4040

4141
/**
4242
* An abstraction of a Java package.
@@ -67,7 +67,7 @@ private JavaPackage(Classes classes, String name, boolean includeSubPackages) {
6767
this.classes = classes;
6868
this.packageClasses = classes.that(resideInAPackage(includeSubPackages ? name.concat("..") : name));
6969
this.name = name;
70-
this.directSubPackages = Suppliers.memoize(() -> packageClasses.stream() //
70+
this.directSubPackages = SingletonSupplier.of(() -> packageClasses.stream() //
7171
.map(it -> it.getPackageName()) //
7272
.filter(it -> !it.equals(name)) //
7373
.map(it -> extractDirectSubPackage(it)) //

spring-modulith-core/src/test/java/org/springframework/modulith/core/TestUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717

1818
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.*;
1919

20+
import java.util.function.Supplier;
21+
2022
import org.jmolecules.ddd.annotation.AggregateRoot;
2123
import org.springframework.data.repository.Repository;
2224
import org.springframework.util.Assert;
25+
import org.springframework.util.function.SingletonSupplier;
2326

2427
import com.tngtech.archunit.base.DescribedPredicate;
2528
import com.tngtech.archunit.core.domain.JavaClass;
2629
import com.tngtech.archunit.core.domain.JavaClasses;
2730
import com.tngtech.archunit.core.importer.ClassFileImporter;
28-
import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier;
29-
import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers;
3031

3132
/**
3233
* Utilities for testing.
@@ -35,13 +36,14 @@
3536
*/
3637
class TestUtils {
3738

38-
private static Supplier<JavaClasses> imported = Suppliers.memoize(() -> new ClassFileImporter() //
39+
private static Supplier<JavaClasses> imported = SingletonSupplier.of(() -> new ClassFileImporter() //
3940
.importPackagesOf(ApplicationModules.class, Repository.class, AggregateRoot.class));
4041

4142
private static DescribedPredicate<JavaClass> IS_MODULE_TYPE = JavaClass.Predicates
4243
.resideInAPackage(ApplicationModules.class.getPackage().getName());
4344

44-
private static Supplier<Classes> classes = Suppliers.memoize(() -> Classes.of(imported.get()).that(IS_MODULE_TYPE));
45+
private static Supplier<Classes> classes = SingletonSupplier
46+
.of(() -> Classes.of(imported.get()).that(IS_MODULE_TYPE));
4547

4648
/**
4749
* Returns all {@link Classes} of this module.

spring-modulith-test/src/main/java/org/springframework/modulith/test/ModuleTestExecution.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Map;
2323
import java.util.Objects;
2424
import java.util.Optional;
25+
import java.util.function.Supplier;
2526
import java.util.stream.Stream;
2627

2728
import org.slf4j.Logger;
@@ -33,9 +34,7 @@
3334
import org.springframework.modulith.core.ApplicationModules;
3435
import org.springframework.modulith.core.JavaPackage;
3536
import org.springframework.modulith.test.ApplicationModuleTest.BootstrapMode;
36-
37-
import com.tngtech.archunit.thirdparty.com.google.common.base.Supplier;
38-
import com.tngtech.archunit.thirdparty.com.google.common.base.Suppliers;
37+
import org.springframework.util.function.SingletonSupplier;
3938

4039
/**
4140
* @author Oliver Drotbohm
@@ -66,7 +65,7 @@ private ModuleTestExecution(ApplicationModuleTest annotation, ApplicationModules
6665

6766
this.extraIncludes = getExtraModules(annotation, modules).toList();
6867

69-
this.basePackages = Suppliers.memoize(() -> {
68+
this.basePackages = SingletonSupplier.of(() -> {
7069

7170
var moduleBasePackages = module.getBootstrapBasePackages(modules, bootstrapMode.getDepth());
7271
var sharedBasePackages = modules.getSharedModules().stream().map(it -> it.getBasePackage());
@@ -77,7 +76,7 @@ private ModuleTestExecution(ApplicationModuleTest annotation, ApplicationModules
7776
return Stream.concat(intermediate, sharedBasePackages).distinct().toList();
7877
});
7978

80-
this.dependencies = Suppliers.memoize(() -> {
79+
this.dependencies = SingletonSupplier.of(() -> {
8180

8281
var bootstrapDependencies = module.getBootstrapDependencies(modules,
8382
bootstrapMode.getDepth());
@@ -89,7 +88,7 @@ private ModuleTestExecution(ApplicationModuleTest annotation, ApplicationModules
8988
}
9089
}
9190

92-
public static java.util.function.Supplier<ModuleTestExecution> of(Class<?> type) {
91+
public static Supplier<ModuleTestExecution> of(Class<?> type) {
9392

9493
return () -> {
9594

0 commit comments

Comments
 (0)