Skip to content

Commit 75fab76

Browse files
gselzerhinerm
authored andcommitted
Add hints option to OpBuilders
1 parent 717465b commit 75fab76

8 files changed

Lines changed: 3141 additions & 8 deletions

File tree

‎scijava/scijava-ops/src/main/java/org/scijava/ops/core/builder/OpBuilder.java‎

Lines changed: 1916 additions & 7 deletions
Large diffs are not rendered by default.

‎scijava/scijava-ops/src/main/java/org/scijava/ops/function/Computers.java‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.function.Consumer;
1616

1717
import org.scijava.ops.OpEnvironment;
18+
import org.scijava.ops.hints.Hints;
1819
import org.scijava.types.Nil;
1920
import org.scijava.param.Container;
2021
import org.scijava.types.Types;
@@ -186,6 +187,108 @@ public static <I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15,
186187
return matchHelper(env, opName, Computers.Arity16.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type, in10Type, in11Type, in12Type, in13Type, in14Type, in15Type, in16Type);
187188
}
188189

190+
@SuppressWarnings("unchecked")
191+
public static <O> Computers.Arity0<O> match(final OpEnvironment env, final String opName, final Nil<O> outType, final Hints hints)
192+
{
193+
return matchHelper(env, opName, hints, Computers.Arity0.class, outType);
194+
}
195+
196+
@SuppressWarnings("unchecked")
197+
public static <I, O> Computers.Arity1<I, O> match(final OpEnvironment env, final String opName, final Nil<I> inType, final Nil<O> outType, final Hints hints)
198+
{
199+
return matchHelper(env, opName, hints, Computers.Arity1.class, outType, inType);
200+
}
201+
202+
@SuppressWarnings("unchecked")
203+
public static <I1, I2, O> Computers.Arity2<I1, I2, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<O> outType, final Hints hints)
204+
{
205+
return matchHelper(env, opName, hints, Computers.Arity2.class, outType, in1Type, in2Type);
206+
}
207+
208+
@SuppressWarnings("unchecked")
209+
public static <I1, I2, I3, O> Computers.Arity3<I1, I2, I3, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<O> outType, final Hints hints)
210+
{
211+
return matchHelper(env, opName, hints, Computers.Arity3.class, outType, in1Type, in2Type, in3Type);
212+
}
213+
214+
@SuppressWarnings("unchecked")
215+
public static <I1, I2, I3, I4, O> Computers.Arity4<I1, I2, I3, I4, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<O> outType, final Hints hints)
216+
{
217+
return matchHelper(env, opName, hints, Computers.Arity4.class, outType, in1Type, in2Type, in3Type, in4Type);
218+
}
219+
220+
@SuppressWarnings("unchecked")
221+
public static <I1, I2, I3, I4, I5, O> Computers.Arity5<I1, I2, I3, I4, I5, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<O> outType, final Hints hints)
222+
{
223+
return matchHelper(env, opName, hints, Computers.Arity5.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type);
224+
}
225+
226+
@SuppressWarnings("unchecked")
227+
public static <I1, I2, I3, I4, I5, I6, O> Computers.Arity6<I1, I2, I3, I4, I5, I6, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<I6> in6Type, final Nil<O> outType, final Hints hints)
228+
{
229+
return matchHelper(env, opName, hints, Computers.Arity6.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type);
230+
}
231+
232+
@SuppressWarnings("unchecked")
233+
public static <I1, I2, I3, I4, I5, I6, I7, O> Computers.Arity7<I1, I2, I3, I4, I5, I6, I7, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<I6> in6Type, final Nil<I7> in7Type, final Nil<O> outType, final Hints hints)
234+
{
235+
return matchHelper(env, opName, hints, Computers.Arity7.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type);
236+
}
237+
238+
@SuppressWarnings("unchecked")
239+
public static <I1, I2, I3, I4, I5, I6, I7, I8, O> Computers.Arity8<I1, I2, I3, I4, I5, I6, I7, I8, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<I6> in6Type, final Nil<I7> in7Type, final Nil<I8> in8Type, final Nil<O> outType, final Hints hints)
240+
{
241+
return matchHelper(env, opName, hints, Computers.Arity8.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type);
242+
}
243+
244+
@SuppressWarnings("unchecked")
245+
public static <I1, I2, I3, I4, I5, I6, I7, I8, I9, O> Computers.Arity9<I1, I2, I3, I4, I5, I6, I7, I8, I9, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<I6> in6Type, final Nil<I7> in7Type, final Nil<I8> in8Type, final Nil<I9> in9Type, final Nil<O> outType, final Hints hints)
246+
{
247+
return matchHelper(env, opName, hints, Computers.Arity9.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type);
248+
}
249+
250+
@SuppressWarnings("unchecked")
251+
public static <I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, O> Computers.Arity10<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<I6> in6Type, final Nil<I7> in7Type, final Nil<I8> in8Type, final Nil<I9> in9Type, final Nil<I10> in10Type, final Nil<O> outType, final Hints hints)
252+
{
253+
return matchHelper(env, opName, hints, Computers.Arity10.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type, in10Type);
254+
}
255+
256+
@SuppressWarnings("unchecked")
257+
public static <I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, O> Computers.Arity11<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<I6> in6Type, final Nil<I7> in7Type, final Nil<I8> in8Type, final Nil<I9> in9Type, final Nil<I10> in10Type, final Nil<I11> in11Type, final Nil<O> outType, final Hints hints)
258+
{
259+
return matchHelper(env, opName, hints, Computers.Arity11.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type, in10Type, in11Type);
260+
}
261+
262+
@SuppressWarnings("unchecked")
263+
public static <I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, O> Computers.Arity12<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<I6> in6Type, final Nil<I7> in7Type, final Nil<I8> in8Type, final Nil<I9> in9Type, final Nil<I10> in10Type, final Nil<I11> in11Type, final Nil<I12> in12Type, final Nil<O> outType, final Hints hints)
264+
{
265+
return matchHelper(env, opName, hints, Computers.Arity12.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type, in10Type, in11Type, in12Type);
266+
}
267+
268+
@SuppressWarnings("unchecked")
269+
public static <I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, O> Computers.Arity13<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<I6> in6Type, final Nil<I7> in7Type, final Nil<I8> in8Type, final Nil<I9> in9Type, final Nil<I10> in10Type, final Nil<I11> in11Type, final Nil<I12> in12Type, final Nil<I13> in13Type, final Nil<O> outType, final Hints hints)
270+
{
271+
return matchHelper(env, opName, hints, Computers.Arity13.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type, in10Type, in11Type, in12Type, in13Type);
272+
}
273+
274+
@SuppressWarnings("unchecked")
275+
public static <I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, O> Computers.Arity14<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<I6> in6Type, final Nil<I7> in7Type, final Nil<I8> in8Type, final Nil<I9> in9Type, final Nil<I10> in10Type, final Nil<I11> in11Type, final Nil<I12> in12Type, final Nil<I13> in13Type, final Nil<I14> in14Type, final Nil<O> outType, final Hints hints)
276+
{
277+
return matchHelper(env, opName, hints, Computers.Arity14.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type, in10Type, in11Type, in12Type, in13Type, in14Type);
278+
}
279+
280+
@SuppressWarnings("unchecked")
281+
public static <I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, O> Computers.Arity15<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<I6> in6Type, final Nil<I7> in7Type, final Nil<I8> in8Type, final Nil<I9> in9Type, final Nil<I10> in10Type, final Nil<I11> in11Type, final Nil<I12> in12Type, final Nil<I13> in13Type, final Nil<I14> in14Type, final Nil<I15> in15Type, final Nil<O> outType, final Hints hints)
282+
{
283+
return matchHelper(env, opName, hints, Computers.Arity15.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type, in10Type, in11Type, in12Type, in13Type, in14Type, in15Type);
284+
}
285+
286+
@SuppressWarnings("unchecked")
287+
public static <I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, O> Computers.Arity16<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, O> match(final OpEnvironment env, final String opName, final Nil<I1> in1Type, final Nil<I2> in2Type, final Nil<I3> in3Type, final Nil<I4> in4Type, final Nil<I5> in5Type, final Nil<I6> in6Type, final Nil<I7> in7Type, final Nil<I8> in8Type, final Nil<I9> in9Type, final Nil<I10> in10Type, final Nil<I11> in11Type, final Nil<I12> in12Type, final Nil<I13> in13Type, final Nil<I14> in14Type, final Nil<I15> in15Type, final Nil<I16> in16Type, final Nil<O> outType, final Hints hints)
288+
{
289+
return matchHelper(env, opName, hints, Computers.Arity16.class, outType, in1Type, in2Type, in3Type, in4Type, in5Type, in6Type, in7Type, in8Type, in9Type, in10Type, in11Type, in12Type, in13Type, in14Type, in15Type, in16Type);
290+
}
291+
189292
@SuppressWarnings({ "unchecked" })
190293
private static <T> T matchHelper(final OpEnvironment env, final String opName, final Class<T> opClass, final Nil<?> outType, final Nil<?>... inTypes)
191294
{
@@ -200,6 +303,20 @@ private static <T> T matchHelper(final OpEnvironment env, final String opName, f
200303
return (T) env.op(opName, Nil.of(specialType), nils, outType);
201304
}
202305

306+
@SuppressWarnings({ "unchecked" })
307+
private static <T> T matchHelper(final OpEnvironment env, final String opName, final Hints hints, final Class<T> opClass, final Nil<?> outType, final Nil<?>... inTypes)
308+
{
309+
final Type[] types = new Type[inTypes.length + 1];
310+
for (int i = 0; i < inTypes.length; i++)
311+
types[i] = inTypes[i].getType();
312+
types[types.length - 1] = outType.getType();
313+
final Type specialType = Types.parameterize(opClass, types);
314+
final Nil<?>[] nils = new Nil[inTypes.length + 1];
315+
System.arraycopy(inTypes, 0, nils, 0, inTypes.length);
316+
nils[nils.length - 1] = outType;
317+
return (T) env.op(opName, Nil.of(specialType), nils, outType, hints);
318+
}
319+
203320
// -- END TEMP --
204321

205322
@FunctionalInterface

0 commit comments

Comments
 (0)