Skip to content

Commit fccc419

Browse files
committed
Unify namespace stream generation
1 parent 28eadb4 commit fccc419

1 file changed

Lines changed: 12 additions & 19 deletions

File tree

scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/simplify/SimplifiedOpDescriptionGenerator.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232
import java.util.ArrayList;
3333
import java.util.List;
34-
import java.util.Optional;
3534
import java.util.stream.Collectors;
35+
import java.util.stream.Stream;
3636

3737
import org.scijava.ops.api.OpEnvironment;
3838
import org.scijava.ops.api.OpInfo;
@@ -41,7 +41,6 @@
4141
import org.scijava.ops.engine.matcher.reduce.ReducedOpInfo;
4242
import org.scijava.ops.engine.util.Infos;
4343
import org.scijava.priority.Priority;
44-
import org.scijava.struct.Member;
4544

4645
/**
4746
* An {@link OpDescriptionGenerator} implementation which makes use of
@@ -96,34 +95,28 @@ public String verboseDescriptions(OpEnvironment env, OpRequest req) {
9695
}
9796

9897
private String allNamespaces(final OpEnvironment env) {
99-
List<String> namespaces = env.infos().stream() //
100-
// Get all names from each Op
101-
.flatMap(info -> info.names().stream()) //
102-
// Map each name to its namespace
103-
.map(name -> name.contains(".") ? name.substring(0, name.indexOf(".")) : name) //
104-
// Deduplicate & sort
105-
.distinct() //
106-
.sorted() //
107-
// Filter out the engine namespaces
108-
.filter(ns -> !ns.equals("engine")) //
98+
List<String> namespaces = namespaceStream(env) //
10999
.collect(Collectors.toList());
110100
return "Namespaces:\n\t> " + String.join("\n\t> ", namespaces);
111101
}
112102

113103
private String allNamespaces(final OpEnvironment env, final String name) {
114-
List<String> namespaces = env.infos().stream() //
104+
List<String> namespaces = namespaceStream(env) //
105+
// Filter by the predicate name
106+
.filter(n -> n.contains(name)) //
107+
.collect(Collectors.toList());
108+
return "Names:\n\t> " + String.join("\n\t> ", namespaces);
109+
}
110+
111+
private Stream<String> namespaceStream(OpEnvironment env) {
112+
return env.infos().stream() //
115113
// Get all names from each Op
116114
.flatMap(info -> info.names().stream()) //
117115
// Deduplicate & sort
118116
.distinct() //
119117
.sorted() //
120118
// Filter out the engine namespace
121-
.filter(ns -> !ns.equals("engine")) //
122-
// Filter by the predicate name
123-
.filter(n -> n.contains(name)) //
124-
.collect(Collectors.toList());
125-
return "Names:\n\t> " + String.join("\n\t> ", namespaces);
126-
119+
.filter(ns -> !ns.equals("engine"));
127120
}
128121

129122
private List<OpInfo> filterInfos(Iterable<? extends OpInfo> infos, OpRequest req) {

0 commit comments

Comments
 (0)