File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
spring-modulith-core/src/main/java/org/springframework/modulith/model
spring-modulith-docs/src/main/java/org/springframework/modulith/docs Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 17
17
18
18
import lombok .RequiredArgsConstructor ;
19
19
20
+ import java .util .HashSet ;
20
21
import java .util .List ;
22
+ import java .util .function .Function ;
21
23
import java .util .stream .Stream ;
22
24
23
25
import org .springframework .util .Assert ;
@@ -73,6 +75,23 @@ public Stream<ApplicationModuleDependency> stream() {
73
75
return dependencies .stream ();
74
76
}
75
77
78
+ /**
79
+ * Return all {@link ApplicationModuleDependency} instances unique by the value extracted using the given
80
+ * {@link Function}.
81
+ *
82
+ * @param extractor will never be {@literal null}.
83
+ * @return will never be {@literal null}.
84
+ */
85
+ public Stream <ApplicationModuleDependency > uniqueStream (Function <ApplicationModuleDependency , Object > extractor ) {
86
+
87
+ Assert .notNull (extractor , "Extractor function must not be null!" );
88
+
89
+ var seenTargets = new HashSet <>();
90
+
91
+ return dependencies .stream ()
92
+ .filter (it -> seenTargets .add (extractor .apply (it )));
93
+ }
94
+
76
95
public ApplicationModuleDependencies withType (DependencyType type ) {
77
96
78
97
var filtered = dependencies .stream ()
Original file line number Diff line number Diff line change 29
29
import org .springframework .modulith .docs .Documenter .CanvasOptions ;
30
30
import org .springframework .modulith .docs .Documenter .CanvasOptions .Groupings ;
31
31
import org .springframework .modulith .model .ApplicationModule ;
32
+ import org .springframework .modulith .model .ApplicationModuleDependency ;
32
33
import org .springframework .modulith .model .ApplicationModules ;
33
34
import org .springframework .modulith .model .ArchitecturallyEvidentType ;
34
35
import org .springframework .modulith .model .DependencyType ;
@@ -363,7 +364,8 @@ public String toAsciidoctor(String source) {
363
364
*/
364
365
public String renderBeanReferences (ApplicationModule module ) {
365
366
366
- var bullets = module .getDependencies (modules , DependencyType .USES_COMPONENT ).stream ()
367
+ var bullets = module .getDependencies (modules , DependencyType .USES_COMPONENT )
368
+ .uniqueStream (ApplicationModuleDependency ::getTargetType )
367
369
.map (it -> "%s (in %s)" .formatted (toInlineCode (it .getTargetType ()), it .getTargetModule ().getDisplayName ()))
368
370
.map (this ::toBulletPoint )
369
371
.collect (Collectors .joining ("\n " ));
You can’t perform that action at this time.
0 commit comments