3232import java .lang .reflect .ParameterizedType ;
3333import java .lang .reflect .Type ;
3434import java .lang .reflect .TypeVariable ;
35- import java .util .*;
35+ import java .util .ArrayList ;
36+ import java .util .Arrays ;
37+ import java .util .Collection ;
38+ import java .util .Collections ;
39+ import java .util .EnumSet ;
40+ import java .util .HashMap ;
41+ import java .util .List ;
42+ import java .util .Map ;
43+ import java .util .Objects ;
44+ import java .util .ServiceLoader ;
45+ import java .util .Set ;
3646import java .util .function .BiConsumer ;
47+ import java .util .function .Function ;
3748import java .util .stream .Collectors ;
3849import java .util .stream .StreamSupport ;
3950
4253import org .scijava .log2 .Logger ;
4354import org .scijava .log2 .StderrLoggerFactory ;
4455import org .scijava .meta .Versions ;
45- import org .scijava .ops .api .*;
46- import org .scijava .ops .api .features .*;
56+ import org .scijava .ops .api .Hints ;
57+ import org .scijava .ops .api .InfoChain ;
58+ import org .scijava .ops .api .InfoChainGenerator ;
59+ import org .scijava .ops .api .OpCandidate ;
60+ import org .scijava .ops .api .OpDependencyMember ;
61+ import org .scijava .ops .api .OpEnvironment ;
62+ import org .scijava .ops .api .OpHistory ;
63+ import org .scijava .ops .api .OpInfo ;
64+ import org .scijava .ops .api .OpInfoGenerator ;
65+ import org .scijava .ops .api .OpInstance ;
66+ import org .scijava .ops .api .OpMetadata ;
67+ import org .scijava .ops .api .OpRef ;
68+ import org .scijava .ops .api .OpWrapper ;
69+ import org .scijava .ops .api .RichOp ;
4770import org .scijava .ops .api .features .BaseOpHints .Adaptation ;
4871import org .scijava .ops .api .features .BaseOpHints .DependencyMatching ;
4972import org .scijava .ops .api .features .BaseOpHints .Simplification ;
73+ import org .scijava .ops .api .features .DependencyMatchingException ;
74+ import org .scijava .ops .api .features .MatchingConditions ;
75+ import org .scijava .ops .api .features .MatchingRoutine ;
76+ import org .scijava .ops .api .features .OpMatcher ;
77+ import org .scijava .ops .api .features .OpMatchingException ;
5078import org .scijava .ops .engine .hint .DefaultHints ;
5179import org .scijava .ops .engine .impl .DependencyRichOpInfoChain ;
5280import org .scijava .ops .engine .impl .LambdaTypeBaker ;
@@ -91,7 +119,7 @@ public class DefaultOpEnvironment implements OpEnvironment {
91119 * search size for any Op request to the number of known Ops with the name
92120 * given in the request.
93121 */
94- private Map <String , Set <OpInfo >> opDirectory ;
122+ private Map <String , List <OpInfo >> opDirectory ;
95123
96124 /**
97125 * Data structure storing all known Ops, discoverable using their id.
@@ -166,30 +194,32 @@ public static List<MatchingRoutine> getMatchingRoutines(
166194 }
167195
168196 @ Override
169- public Set <OpInfo > infos () {
197+ public List <OpInfo > infos () {
170198 if (opDirectory == null ) initOpDirectory ();
171- return opDirectory .values ().stream ().flatMap (Collection ::stream ).collect (
172- Collectors .toSet ());
199+ // NB distinct() prevents aliased Ops from appearing multiple times.
200+ return opDirectory .values ().stream () //
201+ .flatMap (Collection ::stream ).distinct ().sorted ()
202+ .collect (Collectors .toList ());
173203 }
174204
175205 @ Override
176- public Set <OpInfo > infos (String name ) {
206+ public List <OpInfo > infos (String name ) {
177207 if (opDirectory == null ) initOpDirectory ();
178208 if (name == null || name .isEmpty ()) return infos ();
179209 return opsOfName (name );
180210 }
181211
182212 @ Override
183- public Set <OpInfo > infos (Hints hints ) {
213+ public List <OpInfo > infos (Hints hints ) {
184214 return filterInfos (infos (), hints );
185215 }
186216
187217 @ Override
188- public Set <OpInfo > infos (String name , Hints hints ) {
218+ public List <OpInfo > infos (String name , Hints hints ) {
189219 return filterInfos (infos (name ), hints );
190220 }
191221
192- private Set <OpInfo > filterInfos (Set <OpInfo > infos , Hints hints ) {
222+ private List <OpInfo > filterInfos (List <OpInfo > infos , Hints hints ) {
193223 boolean adapting = hints .contains (Adaptation .IN_PROGRESS );
194224 boolean simplifying = hints .contains (Simplification .IN_PROGRESS );
195225 // if we aren't doing any
@@ -201,7 +231,7 @@ private Set<OpInfo> filterInfos(Set<OpInfo> infos, Hints hints) {
201231 // filter out unadaptable ops
202232 .filter (info -> !simplifying || !info .declaredHints ().contains (
203233 Simplification .FORBIDDEN )) //
204- .collect (Collectors .toSet ());
234+ .collect (Collectors .toList ());
205235 }
206236
207237 @ Override
@@ -326,12 +356,12 @@ public Set<OpInfo> infosFrom(Object o) {
326356 }
327357
328358 @ Override
329- public Set <String > descriptions () {
359+ public List <String > descriptions () {
330360 return descriptions (infos ());
331361 }
332362
333363 @ Override
334- public Set <String > descriptions (String name ) {
364+ public List <String > descriptions (String name ) {
335365 return descriptions (infos (name ));
336366 }
337367
@@ -348,10 +378,10 @@ public Set<String> descriptions(String name) {
348378 * @return a {@link Set} of {@link String}s, one describing each
349379 * {@link OpInfo} in {@code infos}.
350380 */
351- private Set <String > descriptions (Iterable <OpInfo > infos ) {
381+ private List <String > descriptions (Iterable <OpInfo > infos ) {
352382 return StreamSupport .stream (infos .spliterator (), true ) //
353383 .map (OpInfo ::toString ) //
354- .collect (Collectors .toSet ());
384+ .collect (Collectors .toList ());
355385 }
356386
357387 @ SuppressWarnings ("unchecked" )
@@ -724,6 +754,13 @@ private synchronized void initIdDirectory() {
724754 .forEach (info -> idDirectory .put (info .id (), info ));
725755 }
726756
757+ /**
758+ * Function for populating opDirectory with new ArrayList.
759+ * Declared only once, right here
760+ */
761+ private final Function <String , List <OpInfo >> nameListCreator = //
762+ (name ) -> new ArrayList <>();
763+
727764 private final BiConsumer <OpInfo , Logger > addToOpIndex = (final OpInfo opInfo , final Logger log ) -> {
728765 if (opInfo .names () == null || opInfo .names ().size () == 0 ) {
729766 log .error ("Skipping Op " + opInfo .implementationName () + ":\n " +
@@ -736,16 +773,16 @@ private synchronized void initIdDirectory() {
736773 return ;
737774 }
738775 for (String opName : opInfo .names ()) {
739- opDirectory .putIfAbsent (opName , new TreeSet <>());
740- boolean success = opDirectory .get (opName ).add (opInfo );
741- if (!success ) System .out .println ("Did not add OpInfo " + opInfo );
776+ opDirectory .computeIfAbsent (opName , nameListCreator ).add (opInfo );
742777 }
743778 };
744779
745- private Set <OpInfo > opsOfName (final String name ) {
746- final Set <OpInfo > ops = opDirectory .getOrDefault (name , Collections
747- .emptySet ());
748- return Collections .unmodifiableSet (ops );
780+ private List <OpInfo > opsOfName (final String name ) {
781+ // NB distinct() prevents aliased Ops from appearing multiple times.
782+ return opDirectory .getOrDefault (name , Collections .emptyList ()).stream () //
783+ .distinct () //
784+ .sorted () //
785+ .collect (Collectors .toUnmodifiableList ());
749786 }
750787
751788 /**
0 commit comments