5858import org .scijava .ops .types .Nil ;
5959
6060/**
61- * Service that manages ops.
61+ * Service to provide a list of available ops structured in a prefix tree and to
62+ * search for ops matching specified types.
6263 *
63- * @author Curtis Rueden
64+ * @author David Kolb
6465 */
6566@ Plugin (type = Service .class )
6667public class OpService extends AbstractService implements SciJavaService , OpEnvironment {
@@ -74,6 +75,9 @@ public class OpService extends AbstractService implements SciJavaService, OpEnvi
7475 @ Parameter
7576 private LogService log ;
7677
78+ /**
79+ * Prefix tree to cache and quickly find {@link OpInfo}s.
80+ */
7781 private PrefixTree <OpInfo > opCache ;
7882
7983 /**
@@ -144,14 +148,14 @@ public <T> StructInstance<T> findOpInstance(final String opName, final Nil<T> sp
144148 }
145149 return opInst ;
146150 }
147-
148- public <T > T findOp (final Nil <T > specialType , final Nil <?>[] inTypes ,
149- final Nil <?>[] outTypes , final Object ... secondaryArgs ) {
151+
152+ public <T > T findOp (final Nil <T > specialType , final Nil <?>[] inTypes , final Nil <?>[] outTypes ,
153+ final Object ... secondaryArgs ) {
150154 return findOpInstance (null , specialType , inTypes , outTypes , secondaryArgs ).object ();
151155 }
152-
153- public <T > T findOp (final Nil <T > specialType , final Nil <?>[] inTypes ,
154- final Nil <?> outType , final Object ... secondaryArgs ) {
156+
157+ public <T > T findOp (final Nil <T > specialType , final Nil <?>[] inTypes , final Nil <?> outType ,
158+ final Object ... secondaryArgs ) {
155159 return findOpInstance (null , specialType , inTypes , new Nil [] { outType }, secondaryArgs ).object ();
156160 }
157161
@@ -173,15 +177,6 @@ public OpCandidate findTypeMatch(final OpRef ref) {
173177 return findTypeMatches (ref ).singleMatch ();
174178 }
175179
176- private Type [] merge (Type in1 , Type ... ins ) {
177- Type [] merged = new Type [ins .length + 1 ];
178- merged [0 ] = in1 ;
179- for (int i = 0 ; i < ins .length ; i ++) {
180- merged [i + 1 ] = ins [i ];
181- }
182- return merged ;
183- }
184-
185180 private Type [] toTypes (Nil <?>... nils ) {
186181 return Arrays .stream (nils ).filter (n -> n != null ).map (n -> n .getType ()).toArray (Type []::new );
187182 }
@@ -206,19 +201,25 @@ private void addAliases(String[] opNames) {
206201 }
207202 }
208203
209- private static String getIndent (int num ) {
204+ /**
205+ * Constructs a string with the specified number of tabs '\t'.
206+ *
207+ * @param numOfTabs
208+ * @return
209+ */
210+ private static String getIndent (int numOfTabs ) {
210211 String str = "" ;
211- for (int i = 0 ; i < num ; i ++) {
212+ for (int i = 0 ; i < numOfTabs ; i ++) {
212213 str += "\t " ;
213214 }
214215 return str ;
215216 }
216217
217218 /**
218219 * Class to represent a query for a {@link PrefixTree}. Prefixes must be
219- * separated by dots ('.'). E.g. 'math.add'.
220- *
221- * @author David Kolb
220+ * separated by dots ('.'). E.g. 'math.add'. These queries are used in
221+ * order to specify the level where elements should be inserted into or
222+ * retrieved from the tree.
222223 */
223224 private static class PrefixQuery {
224225 String cachedToString ;
@@ -287,20 +288,22 @@ public String toString() {
287288 *
288289 * <pre>
289290 * Prefix: Elem:
290- * math.add obj1
291- * math.add obj2
292- * math.sqrt obj3
293- * math obj4
294- * obj5
291+ * " math.add" obj1
292+ * " math.add" obj2
293+ * " math.sqrt" obj3
294+ * " math" obj4
295+ * "" obj5
295296 * </pre>
296297 *
297298 * Will result in the following tree:
298299 *
299300 * <pre>
300301 * root [obj5]
301302 * |
303+ * |
302304 * math [obj4]
303305 * / \
306+ * / \
304307 * add [obj1, obj2] sqrt [obj3]
305308 * </pre>
306309 *
@@ -343,7 +346,8 @@ private void add(PrefixQuery query, PrefixNode<T> node, T data) {
343346 * this class would return all elements contained in the tree except for
344347 * 'obj5'. 'math.add' would only return 'obj1' and 'obj2'. This method
345348 * returns an iterable over these elements in O(# number of all nodes
346- * below query).
349+ * below query). The number of nodes is the number of distinct prefixes
350+ * below the specified query.
347351 *
348352 * @param query
349353 * @return
0 commit comments