Skip to content

Commit ec5bc7f

Browse files
committed
Restructure functional interfaces and related code
The Consumer*, Computer*, Function* and Inplace* interfaces have been consolidated into umbrella container classes Consumers, Computers, Functions and Inplaces respectively in the function subpackage. This naming mirrors java.util.function for functional interfaces in core. The previous Computers, Functions and Inplaces classes in the util subpackage have been merged into the new container classes. The unary, binary, ternary, etc., lookups have all been renamed to match (or match1, match2, etc., in the case of Inplaces), to communicate more uniformly that these are shorthands for matching. The Source interface has been renamed to Producer, because it has many fewer name clashes, and reduces semantic ambiguity. The GenericTyped wrapper ops in the ComputerOps, FunctionOps, InplaceOps and SourceOp classes (as well as the unused/orphaned GenericComputers, GenericFunctions, GenericInplaces and GenericSourceOp classes) have been consolidated into a single GenericTypedOps container class in the function subpackage. For the moment the nested classes there are public, but only temporarily until the op wrapping logic can be refactored out of the OpService itself and into the same package as those classes. To avoid name clashes across packages, the Computers, Functions and Inplaces nested classes inside Maps and Adapt have been renamed to have unique suffixes: Maps.Functions beame Maps.FunctionMaps, etc. These names are merely transitional for the moment, and may change again soon. Finally, the @parameter annotations have been removed from OpCollection ops that do not need them, since they are inferred by default now -- although there are a few places where the @parameter annotations could not be removed yet due to limitations in the inference behavior.
1 parent 63feed2 commit ec5bc7f

116 files changed

Lines changed: 1429 additions & 5956 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/org/scijava/ops/OpService.java

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -48,49 +48,22 @@
4848
import org.scijava.log.LogService;
4949
import org.scijava.ops.core.Op;
5050
import org.scijava.ops.core.OpCollection;
51-
import org.scijava.ops.core.computer.ComputerOps.BiComputerOp;
52-
import org.scijava.ops.core.computer.ComputerOps.Computer3Op;
53-
import org.scijava.ops.core.computer.ComputerOps.Computer4Op;
54-
import org.scijava.ops.core.computer.ComputerOps.Computer5Op;
55-
import org.scijava.ops.core.computer.ComputerOps.Computer6Op;
56-
import org.scijava.ops.core.computer.ComputerOps.Computer7Op;
57-
import org.scijava.ops.core.computer.ComputerOps.Computer8Op;
58-
import org.scijava.ops.core.computer.ComputerOps.ComputerOp;
59-
import org.scijava.ops.core.function.FunctionOps.BiFunctionOp;
60-
import org.scijava.ops.core.function.FunctionOps.Function3Op;
61-
import org.scijava.ops.core.function.FunctionOps.Function4Op;
62-
import org.scijava.ops.core.function.FunctionOps.Function5Op;
63-
import org.scijava.ops.core.function.FunctionOps.Function6Op;
64-
import org.scijava.ops.core.function.FunctionOps.Function7Op;
65-
import org.scijava.ops.core.function.FunctionOps.Function8Op;
66-
import org.scijava.ops.core.function.FunctionOps.Function9Op;
67-
import org.scijava.ops.core.function.FunctionOps.FunctionOp;
68-
import org.scijava.ops.core.function.SourceOp;
69-
import org.scijava.ops.core.inplace.InplaceOps.BiInplaceFirstOp;
70-
import org.scijava.ops.core.inplace.InplaceOps.BiInplaceSecondOp;
71-
import org.scijava.ops.core.inplace.InplaceOps.Inplace3FirstOp;
72-
import org.scijava.ops.core.inplace.InplaceOps.Inplace3SecondOp;
73-
import org.scijava.ops.core.inplace.InplaceOps.Inplace3ThirdOp;
74-
import org.scijava.ops.core.inplace.InplaceOps.Inplace4FirstOp;
75-
import org.scijava.ops.core.inplace.InplaceOps.Inplace5FirstOp;
76-
import org.scijava.ops.core.inplace.InplaceOps.Inplace6FirstOp;
77-
import org.scijava.ops.core.inplace.InplaceOps.Inplace7SecondOp;
78-
import org.scijava.ops.core.inplace.InplaceOps.InplaceOp;
51+
import org.scijava.ops.function.GenericTypedOp;
7952
import org.scijava.ops.matcher.DefaultOpMatcher;
8053
import org.scijava.ops.matcher.OpCandidate;
8154
import org.scijava.ops.matcher.OpClassInfo;
8255
import org.scijava.ops.matcher.OpFieldInfo;
8356
import org.scijava.ops.matcher.OpInfo;
57+
import org.scijava.ops.matcher.OpMatcher;
8458
import org.scijava.ops.matcher.OpMatchingException;
8559
import org.scijava.ops.matcher.OpRef;
86-
import org.scijava.ops.matcher.OpMatcher;
8760
import org.scijava.ops.transform.DefaultOpTransformationMatcher;
8861
import org.scijava.ops.transform.OpRunner;
8962
import org.scijava.ops.transform.OpTransformationCandidate;
9063
import org.scijava.ops.transform.OpTransformationException;
91-
import org.scijava.ops.types.Any;
9264
import org.scijava.ops.transform.OpTransformationMatcher;
9365
import org.scijava.ops.transform.OpTransformer;
66+
import org.scijava.ops.types.Any;
9467
import org.scijava.ops.types.Nil;
9568
import org.scijava.ops.types.TypeService;
9669
import org.scijava.param.FunctionalMethodType;
@@ -146,34 +119,20 @@ public class OpService extends AbstractService implements SciJavaService, OpEnvi
146119
private static Map<Class<?>, Class<?>> wrappers() {
147120
final Map<Class<?>, Class<?>> result = new HashMap<>();
148121
final Class<?>[] wrapperClasses = { //
149-
FunctionOp.class, //
150-
BiFunctionOp.class, //
151-
Function3Op.class, //
152-
Function4Op.class, //
153-
Function5Op.class, //
154-
Function6Op.class, //
155-
Function7Op.class, //
156-
Function8Op.class, //
157-
Function9Op.class, //
158-
ComputerOp.class, //
159-
BiComputerOp.class, //
160-
Computer3Op.class, //
161-
Computer4Op.class, //
162-
Computer5Op.class, //
163-
Computer6Op.class, //
164-
Computer7Op.class, //
165-
Computer8Op.class, //
166-
InplaceOp.class, //
167-
BiInplaceFirstOp.class, //
168-
BiInplaceSecondOp.class, //
169-
Inplace3FirstOp.class, //
170-
Inplace3SecondOp.class, //
171-
Inplace3ThirdOp.class, //
172-
Inplace4FirstOp.class, //
173-
Inplace5FirstOp.class, //
174-
Inplace6FirstOp.class, //
175-
Inplace7SecondOp.class, //
176-
SourceOp.class
122+
GenericTypedOp.P.class, //
123+
GenericTypedOp.F1.class, //
124+
GenericTypedOp.F2.class, //
125+
GenericTypedOp.F3.class, //
126+
GenericTypedOp.C0.class, //
127+
GenericTypedOp.C1.class, //
128+
GenericTypedOp.C2.class, //
129+
GenericTypedOp.C3.class, //
130+
GenericTypedOp.IP1.class, //
131+
GenericTypedOp.IP2_1.class, //
132+
GenericTypedOp.IP2_2.class, //
133+
GenericTypedOp.IP3_1.class, //
134+
GenericTypedOp.IP3_2.class, //
135+
GenericTypedOp.IP3_3.class //
177136
};
178137
for (final Class<?> c : wrapperClasses) {
179138
result.put(c.getInterfaces()[0], c);
@@ -409,7 +368,9 @@ private Object wrapOp(Object op, OpCandidate match, OpTransformationCandidate tr
409368
"Matched op Type " + type.getClass() + " matches multiple Op types: " + wrappers.toString());
410369
// get the wrapper and wrap up the Op
411370
Class<?> wrapper = wrappers.get(suitableWrappers[0]);
412-
return wrapper.getConstructors()[0].newInstance(op, type, opInfo);
371+
// CTR FIXME: Instead of using reflection, register constructors
372+
// as BiFunction<OP, OpInfo, GenericOp<OP>> via ::new syntax.
373+
return wrapper.getConstructors()[0].newInstance(op, opInfo);
413374
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
414375
| SecurityException exc) {
415376
log.error(exc.getMessage() != null ? exc.getMessage() : "Cannot wrap " + op.getClass());

src/main/java/org/scijava/ops/copy/CopyOpCollection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.scijava.core.Priority;
44
import org.scijava.ops.OpField;
55
import org.scijava.ops.core.OpCollection;
6-
import org.scijava.ops.core.computer.Computer;
6+
import org.scijava.ops.function.Computers;
77
import org.scijava.param.Parameter;
88
import org.scijava.plugin.Plugin;
99
import org.scijava.struct.ItemIO;
@@ -14,7 +14,7 @@ public class CopyOpCollection {
1414
@OpField(names = "cp, copy", priority = Priority.LOW)
1515
@Parameter(key = "array")
1616
@Parameter(key = "arrayCopy", itemIO = ItemIO.BOTH)
17-
public static final Computer<double[], double[]> copyPrimitiveDoubleArray = (from, to) -> {
17+
public static final Computers.Arity1<double[], double[]> copyPrimitiveDoubleArray = (from, to) -> {
1818
for (int i = 0; i < to.length; i++) {
1919
to[i] = from[i];
2020
}
@@ -23,7 +23,7 @@ public class CopyOpCollection {
2323
@OpField(names = "cp, copy", priority = Priority.LOW)
2424
@Parameter(key = "array")
2525
@Parameter(key = "arrayCopy", itemIO = ItemIO.BOTH)
26-
public static final Computer<Double[], Double[]> copyDoubleArray = (from, to) -> {
26+
public static final Computers.Arity1<Double[], Double[]> copyDoubleArray = (from, to) -> {
2727
for (int i = 0; i < to.length; i++) {
2828
to[i] = from[i];
2929
}

src/main/java/org/scijava/ops/core/Consumer10.java

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/main/java/org/scijava/ops/core/Consumer12.java

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)