Skip to content

Commit df05642

Browse files
Treiblesschorlectrueden
authored andcommitted
Remove enum identifying ops and only use Strings
1 parent 54a48a7 commit df05642

17 files changed

Lines changed: 96 additions & 93 deletions

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141

4242
import org.scijava.InstantiableException;
4343
import org.scijava.log.LogService;
44-
import org.scijava.ops.Ops.OpIdentifier;
4544
import org.scijava.ops.core.Op;
4645
import org.scijava.ops.core.OpCollection;
4746
import org.scijava.ops.matcher.MatchingResult;
@@ -188,22 +187,12 @@ public <T> T findOp(final Nil<T> specialType, final Nil<?>[] inTypes, final Nil<
188187
return findOpInstance(null, specialType, inTypes, new Nil[] { outType }, secondaryArgs).object();
189188
}
190189

191-
public <T> T findOp(final OpIdentifier op, final Nil<T> specialType, final Nil<?>[] inTypes,
192-
final Nil<?>[] outTypes, final Object... secondaryArgs) {
193-
return findOpInstance(op.getName(), specialType, inTypes, outTypes, secondaryArgs).object();
194-
}
195-
196-
public <T, E extends OpIdentifier> T findOp(final OpIdentifier op, final Nil<T> specialType, final Nil<?>[] inTypes,
197-
final Nil<?> outType, final Object... secondaryArgs) {
198-
return findOpInstance(op.getName(), specialType, inTypes, new Nil[] { outType }, secondaryArgs).object();
199-
}
200-
201190
public <T> T findOp(final String opName, final Nil<T> specialType, final Nil<?>[] inTypes, final Nil<?>[] outTypes,
202191
final Object... secondaryArgs) {
203192
return findOpInstance(opName, specialType, inTypes, outTypes, secondaryArgs).object();
204193
}
205194

206-
public <T, E extends OpIdentifier> T findOp(final String opName, final Nil<T> specialType, final Nil<?>[] inTypes,
195+
public <T> T findOp(final String opName, final Nil<T> specialType, final Nil<?>[] inTypes,
207196
final Nil<?> outType, final Object... secondaryArgs) {
208197
return findOpInstance(opName, specialType, inTypes, new Nil[] { outType }, secondaryArgs).object();
209198
}
@@ -261,9 +250,9 @@ private static String getIndent(int numOfTabs) {
261250

262251
/**
263252
* Class to represent a query for a {@link PrefixTree}. Prefixes must be
264-
* separated by dots ('.'). E.g. 'math.add'. These queries are used in
265-
* order to specify the level where elements should be inserted into or
266-
* retrieved from the tree.
253+
* separated by dots ('.'). E.g. 'math.add'. These queries are used in order
254+
* to specify the level where elements should be inserted into or retrieved
255+
* from the tree.
267256
*/
268257
private static class PrefixQuery {
269258
String cachedToString;

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

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

src/main/java/org/scijava/ops/math/Add.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
public class Add {
1919

20-
public static final String NAMES = "math.add, math.sum";
20+
public static final String NAMES = MathOps.ADD;
2121

2222
// --------- Functions ---------
2323

src/main/java/org/scijava/ops/math/MathOpCollection.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@
1818
@Plugin(type = OpCollection.class)
1919
public class MathOpCollection {
2020

21-
@OpField(names = "math.add", priority = Priority.LOW)
21+
@OpField(names = MathOps.ADD, priority = Priority.LOW)
2222
@Parameter(key = "number1")
2323
@Parameter(key = "number2")
2424
@Parameter(key = "result", type = ItemIO.OUTPUT)
2525
public static final BiFunction<Double, Double, Double> addDoublesFunction = (x, y) -> x + y;
2626

27-
@OpField(names = "math.add", priority = Priority.HIGH)
27+
@OpField(names = MathOps.ADD, priority = Priority.HIGH)
2828
@Parameter(key = "number1")
2929
@Parameter(key = "number2")
3030
@Parameter(key = "result", type = ItemIO.OUTPUT)
3131
public static final BinaryOperator<Double> addDoublesOperator = (x, y) -> x + y;
3232

33-
@OpField(names = "math.sub")
33+
@OpField(names = MathOps.SUB)
3434
@Parameter(key = "number1")
3535
@Parameter(key = "number2")
3636
@Parameter(key = "result", type = ItemIO.OUTPUT)
3737
public static final BiFunction<Double, Double, Double> subDoublesFunction = (t, u) -> t - u;
3838

39-
@OpField(names = "math.mul")
39+
@OpField(names = MathOps.MUL)
4040
@Parameter(key = "number1")
4141
@Parameter(key = "number2")
4242
@Parameter(key = "result", type = ItemIO.OUTPUT)
4343
public static final BiFunction<Double, Double, Double> mulDoublesFunction = (t, u) -> t * u;
4444

45-
@OpField(names = "math.div")
45+
@OpField(names = MathOps.DIV)
4646
@Parameter(key = "number1")
4747
@Parameter(key = "number2")
4848
@Parameter(key = "result", type = ItemIO.OUTPUT)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.scijava.ops.math;
2+
3+
public class MathOps {
4+
public final static String ADD = "math.add";
5+
public final static String SUB = "math.sub, math.substract";
6+
public final static String DIV = "math.div, math.divide";
7+
public final static String MUL = "math.mul, math.multiply";
8+
public final static String POW = "math.pow, math.power";
9+
public final static String SQRT = "math.sqrt";
10+
public final static String ZERO = "math.zero";
11+
}

src/main/java/org/scijava/ops/math/Power.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
public class Power {
1313

14-
public static final String NAMES = "math.pow";
14+
public static final String NAMES = MathOps.POW;
1515

1616
@Plugin(type = Op.class, name = NAMES)
1717
@Parameter(key = "number")

src/main/java/org/scijava/ops/math/Sqrt.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
public class Sqrt {
1414

15-
public static final String NAMES = "math.sqrt";
15+
public static final String NAMES = MathOps.SQRT;
1616

1717
// --------- Functions ---------
1818

src/main/java/org/scijava/ops/math/Zero.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class Zero {
1212

13-
public static final String NAMES = "math.zero";
13+
public static final String NAMES = MathOps.ZERO;
1414

1515
// --------- Computers ---------
1616

src/main/java/org/scijava/ops/util/Computers.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.lang.reflect.Type;
44

55
import org.scijava.ops.OpService;
6-
import org.scijava.ops.Ops.OpIdentifier;
76
import org.scijava.ops.core.BiComputer;
87
import org.scijava.ops.core.Computer;
98
import org.scijava.ops.core.Op;
@@ -19,7 +18,7 @@ private Computers() {
1918
// NB: Prevent instantiation of utility class.
2019
}
2120

22-
public static <I, O> Computer<I, O> unary(final OpService ops, final OpIdentifier op,
21+
public static <I, O> Computer<I, O> unary(final OpService ops, final String opName,
2322
final Nil<I> inputType, final Nil<O> outputType, final Object... secondaryArgs) {
2423

2524
Nil<Computer<I, O>> computerNil = new Nil<Computer<I, O>>() {
@@ -30,14 +29,14 @@ public Type getType() {
3029
};
3130

3231
return ops.findOp( //
33-
op, //
32+
opName, //
3433
computerNil, //
3534
new Nil[] { inputType, outputType }, //
3635
new Nil[] { outputType }, //
3736
secondaryArgs);
3837
}
3938

40-
public static <I1, I2, O> BiComputer<I1, I2, O> binary(final OpService ops, final OpIdentifier op,
39+
public static <I1, I2, O> BiComputer<I1, I2, O> binary(final OpService ops, final String opName,
4140
final Nil<I1> input1Type, final Nil<I2> input2Type, final Nil<O> outputType,
4241
final Object... secondaryArgs) {
4342

@@ -50,7 +49,7 @@ public Type getType() {
5049
};
5150

5251
return ops.findOp( //
53-
op, //
52+
opName, //
5453
computerNil, //
5554
new Nil[] { input1Type, input2Type, outputType }, //
5655
new Nil[] { outputType }, //

src/main/java/org/scijava/ops/util/Functions.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.function.Function;
66

77
import org.scijava.ops.OpService;
8-
import org.scijava.ops.Ops.OpIdentifier;
98
import org.scijava.ops.core.Op;
109
import org.scijava.ops.types.Nil;
1110
import org.scijava.util.Types;
@@ -19,7 +18,7 @@ private Functions() {
1918
// NB: Prevent instantiation of utility class.
2019
}
2120

22-
public static <I, O> Function<I, O> unary(final OpService ops, final OpIdentifier op,
21+
public static <I, O> Function<I, O> unary(final OpService ops, final String opName,
2322
final Nil<I> inputType, final Nil<O> outputType, final Object... secondaryArgs) {
2423

2524
Nil<Function<I, O>> functionNil = new Nil<Function<I, O>>() {
@@ -30,14 +29,14 @@ public Type getType() {
3029
};
3130

3231
return ops.findOp( //
33-
op, //
32+
opName, //
3433
functionNil, //
3534
new Nil[] { inputType }, //
3635
new Nil[] { outputType }, //
3736
secondaryArgs);
3837
}
3938

40-
public static <I1, I2, O> BiFunction<I1, I2, O> binary(final OpService ops, final OpIdentifier op,
39+
public static <I1, I2, O> BiFunction<I1, I2, O> binary(final OpService ops, final String opName,
4140
final Nil<I1> input1Type, final Nil<I2> input2Type, final Nil<O> outputType,
4241
final Object... secondaryArgs) {
4342

@@ -50,7 +49,7 @@ public Type getType() {
5049
};
5150

5251
return ops.findOp( //
53-
op, //
52+
opName, //
5453
functionNil, //
5554
new Nil[] { input1Type, input2Type }, //
5655
new Nil[] { outputType }, //

0 commit comments

Comments
 (0)