11package org .scijava .ops .util ;
22
3+ import java .lang .reflect .ParameterizedType ;
4+ import java .lang .reflect .Type ;
35import java .util .function .BiFunction ;
46import java .util .function .Function ;
57
68import org .scijava .ops .Op ;
79import org .scijava .ops .base .OpService ;
810import org .scijava .ops .types .Nil ;
11+ import org .scijava .util .Types ;
912
1013/**
1114 * Utility providing adaptation between {@link Op} types.
@@ -18,10 +21,17 @@ private Functions() {
1821
1922 public static <I , O > Function <I , O > unary (final OpService ops , final Class <? extends Op > opClass ,
2023 final Nil <I > inputType , final Nil <O > outputType , final Object ... secondaryArgs ) {
24+
25+ Nil <Function <I , O >> functionNil = new Nil <Function <I , O >>() {
26+ @ Override
27+ public Type getType () {
28+ return Types .parameterize (Function .class , new Type [] { inputType .getType (), outputType .getType () });
29+ }
30+ };
31+
2132 return ops .findOp ( //
2233 opClass , //
23- new Nil <Function <I , O >>() {
24- }, //
34+ functionNil , //
2535 new Nil [] { inputType }, //
2636 new Nil [] { outputType }, //
2737 secondaryArgs );
@@ -31,18 +41,17 @@ public static <I1, I2, O> BiFunction<I1, I2, O> binary(final OpService ops, fina
3141 final Nil <I1 > input1Type , final Nil <I2 > input2Type , final Nil <O > outputType ,
3242 final Object ... secondaryArgs ) {
3343
34- // Parameterize special type corresponding to this method with in/out types. Then we do not have to specify them
35- // explicitly anymore? Also, outside of this 'Functions' convenience thing, one could just search for the deeply
36- // typed (having all type variables bound to a specific type) special type. As we are using Types.satisfies, this
37- // should be type safe. Hence, we could allow to not specify the ins/outs if the special type does not contain
38- // type variables.
39- // ParameterizedType parameterizedBiFuncType = Types.parameterize(BiFunction.class,
40- // new Type[] { input1Type.getType(), input2Type.getType(), outputType.getType() }) ;
44+ Nil < BiFunction < I1 , I2 , O >> functionNil = new Nil < BiFunction < I1 , I2 , O >>() {
45+ @ Override
46+ public Type getType () {
47+ return Types . parameterize ( BiFunction . class ,
48+ new Type [] { input1Type . getType (), input2Type . getType (), outputType . getType () });
49+ }
50+ } ;
4151
4252 return ops .findOp ( //
4353 opClass , //
44- new Nil <BiFunction <I1 , I2 , O >>() {
45- }, //
54+ functionNil , //
4655 new Nil [] { input1Type , input2Type }, //
4756 new Nil [] { outputType }, //
4857 secondaryArgs );
0 commit comments