GH-74 - Bean references in Application Module Canvas now get de-duplicated.

This commit is contained in:
Oliver Drotbohm
2022-11-18 00:13:05 +01:00
parent 9d95d8715d
commit 22993f43d9
2 changed files with 22 additions and 1 deletions

View File

@@ -17,7 +17,9 @@ package org.springframework.modulith.model;
import lombok.RequiredArgsConstructor;
import java.util.HashSet;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
import org.springframework.util.Assert;
@@ -73,6 +75,23 @@ public class ApplicationModuleDependencies {
return dependencies.stream();
}
/**
* Return all {@link ApplicationModuleDependency} instances unique by the value extracted using the given
* {@link Function}.
*
* @param extractor will never be {@literal null}.
* @return will never be {@literal null}.
*/
public Stream<ApplicationModuleDependency> uniqueStream(Function<ApplicationModuleDependency, Object> extractor) {
Assert.notNull(extractor, "Extractor function must not be null!");
var seenTargets = new HashSet<>();
return dependencies.stream()
.filter(it -> seenTargets.add(extractor.apply(it)));
}
public ApplicationModuleDependencies withType(DependencyType type) {
var filtered = dependencies.stream()