Skip to content

Commit 102ef32

Browse files
ctruedengselzer
authored andcommitted
OpBuilder: always be explicit about op type
The op() method is nice and succinct, but it's only unambiguous in certain cases. In others, you have to say which type you want back. So let's just be consistently explicit about it.
1 parent 4370825 commit 102ef32

2 files changed

Lines changed: 28 additions & 28 deletions

File tree

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public <O> Arity0_OT<O> outType(final Nil<O> outType) {
125125
return new Arity0_OT<>(outType);
126126
}
127127

128-
public Producer<?> op() {
128+
public Producer<?> producer() {
129129
final Nil<Producer<Object>> specialType = new Nil<Producer<Object>>() {
130130
@Override
131131
public Type getType() {
@@ -136,7 +136,7 @@ public Type getType() {
136136
}
137137

138138
public Object create() {
139-
return op().create();
139+
return producer().create();
140140
}
141141
}
142142

@@ -187,12 +187,12 @@ public Arity0_OV(final O out) {
187187
this.out = new WeakReference<>(out);
188188
}
189189

190-
public Arity0<O> op() {
190+
public Arity0<O> computer() {
191191
return Computers.match(ops, opName, type(out));
192192
}
193193

194194
public void compute() {
195-
op().compute(out.get());
195+
computer().compute(out.get());
196196
}
197197
}
198198

@@ -244,7 +244,7 @@ public <O> Arity1_IT_OT<I, O> outType(final Nil<O> outType) {
244244
return new Arity1_IT_OT<>(inType, outType);
245245
}
246246

247-
public Function<I, ?> op() {
247+
public Function<I, ?> function() {
248248
return Functions.match(ops, opName, inType, Nil.of(Object.class));
249249
}
250250
}
@@ -266,12 +266,12 @@ public Arity1_IV_OT(final I in, final Nil<O> outType) {
266266
this.outType = outType;
267267
}
268268

269-
public Function<I, O> op() {
269+
public Function<I, O> function() {
270270
return Functions.match(ops, opName, type(in), outType);
271271
}
272272

273273
public O apply() {
274-
return op().apply(in.get());
274+
return function().apply(in.get());
275275
}
276276
}
277277

@@ -301,12 +301,12 @@ public <O> Arity1_IV_OT<I, O> outType(final Nil<O> outType) {
301301
return new Arity1_IV_OT<>(in.get(), outType);
302302
}
303303

304-
public Function<I, ?> op() {
304+
public Function<I, ?> function() {
305305
return Functions.match(ops, opName, type(in), Nil.of(Object.class));
306306
}
307307

308308
public Object apply() {
309-
return op().apply(in.get());
309+
return function().apply(in.get());
310310
}
311311
}
312312

@@ -326,12 +326,12 @@ public Arity1_IV_OV(final I in, final O out) {
326326
this.out = new WeakReference<>(out);
327327
}
328328

329-
public Computers.Arity1<I, O> op() {
329+
public Computers.Arity1<I, O> computer() {
330330
return Computers.match(ops, opName, type(in), type(out));
331331
}
332332

333333
public void compute() {
334-
op().compute(in.get(), out.get());
334+
computer().compute(in.get(), out.get());
335335
}
336336
}
337337

@@ -389,7 +389,7 @@ public <O> Arity2_IT_OT<I1, I2, O> outType(final Nil<O> outType) {
389389
return new Arity2_IT_OT<>(in1Type, in2Type, outType);
390390
}
391391

392-
public BiFunction<I1, I2, ?> op() {
392+
public BiFunction<I1, I2, ?> function() {
393393
return Functions.match(ops, opName, in1Type, in2Type, Nil.of(Object.class));
394394
}
395395
}
@@ -414,12 +414,12 @@ public Arity2_IV_OT(final I1 in1, final I2 in2, final Nil<O> outType) {
414414
this.outType = outType;
415415
}
416416

417-
public BiFunction<I1, I2, O> op() {
417+
public BiFunction<I1, I2, O> function() {
418418
return Functions.match(ops, opName, type(in1), type(in2), outType);
419419
}
420420

421421
public O apply() {
422-
return op().apply(in1.get(), in2.get());
422+
return function().apply(in1.get(), in2.get());
423423
}
424424
}
425425

@@ -452,12 +452,12 @@ public <O> Arity2_IV_OT<I1, I2, O> outType(final Nil<O> outType) {
452452
return new Arity2_IV_OT<>(in1.get(), in2.get(), outType);
453453
}
454454

455-
public BiFunction<I1, I2, ?> op() {
455+
public BiFunction<I1, I2, ?> function() {
456456
return Functions.match(ops, opName, type(in1), type(in2), Nil.of(Object.class));
457457
}
458458

459459
public Object apply() {
460-
return op().apply(in1.get(), in2.get());
460+
return function().apply(in1.get(), in2.get());
461461
}
462462
}
463463

@@ -481,12 +481,12 @@ public Arity2_IV_OV(final I1 in1, final I2 in2, final O out) {
481481
this.out = new WeakReference<>(out);
482482
}
483483

484-
public Computers.Arity2<I1, I2, O> op() {
484+
public Computers.Arity2<I1, I2, O> computer() {
485485
return Computers.match(ops, opName, type(in1), type(in2), type(out));
486486
}
487487

488488
public void compute() {
489-
op().compute(in1.get(), in2.get(), out.get());
489+
computer().compute(in1.get(), in2.get(), out.get());
490490
}
491491
}
492492
}

src/test/java/org/scijava/ops/core/builder/OpBuilderTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void testArity0_OV_run() {
8282
/** Matches a nullary function in a vacuum. */
8383
@Test
8484
public void testArity0_OU_match() {
85-
final Producer<?> op = name("test.helloWorld").input().op();
85+
final Producer<?> op = name("test.helloWorld").input().producer();
8686
final Object result = op.create();
8787
assertEquals("Hello, world!", result);
8888
}
@@ -102,7 +102,7 @@ public void testArity0_OV_match() {
102102
final double[] result = new double[10];
103103
Arrays.fill(result, 12345);
104104
final Computers.Arity0<double[]> op = //
105-
name("math.zero").input().output(result).op();
105+
name("math.zero").input().output(result).computer();
106106
op.compute(result);
107107
assertTrue(Arrays.stream(result).allMatch(v -> v == 0));
108108
}
@@ -136,7 +136,7 @@ public void testArity1_IV_OV_run() {
136136
@Test
137137
public void testArity1_IT_OU_match() {
138138
final Function<Double, ?> op = //
139-
name("math.sqrt").inType(Double.class).op();
139+
name("math.sqrt").inType(Double.class).function();
140140
final Object result = op.apply(16.);
141141
assertEquals(4., result);
142142
}
@@ -164,7 +164,7 @@ public void testArity1_IT_OT_matchF() {
164164
@Test
165165
public void testArity1_IV_OU_match() {
166166
final Function<Double, ?> op = //
167-
name("math.sqrt").input(36.).op();
167+
name("math.sqrt").input(36.).function();
168168
final Object result = op.apply(49.);
169169
assertEquals(7., result);
170170
}
@@ -173,7 +173,7 @@ public void testArity1_IV_OU_match() {
173173
@Test
174174
public void testArity1_IV_OT_match() {
175175
final Function<Double, Double> op = //
176-
name("math.sqrt").input(64.).outType(Double.class).op();
176+
name("math.sqrt").input(64.).outType(Double.class).function();
177177
final double result = op.apply(81.);
178178
assertEquals(9., result, 0.);
179179
}
@@ -183,7 +183,7 @@ public void testArity1_IV_OT_match() {
183183
public void testArity1_IV_OV_match() {
184184
final int[] result = new int[halves.length];
185185
final Computers.Arity1<double[], int[]> op = //
186-
name("test.castToInt").input(halves).output(result).op();
186+
name("test.castToInt").input(halves).output(result).computer();
187187
op.compute(halves, result);
188188
for (int i = 0; i < result.length; i++)
189189
assertEquals((int) halves[i], result[i]);
@@ -220,7 +220,7 @@ public void testArity2_IV_OV_run() {
220220
@Test
221221
public void testArity2_IT_OU_match() {
222222
final BiFunction<Double, Double, ?> op = //
223-
name("math.add").inType(Double.class, Double.class).op();
223+
name("math.add").inType(Double.class, Double.class).function();
224224
final Object result = op.apply(5., 6.);
225225
assertEquals(11., result);
226226
}
@@ -251,7 +251,7 @@ public void testArity2_IT_OT_matchF() {
251251
@Test
252252
public void testArity2_IV_OU_match() {
253253
final BiFunction<Double, Double, ?> op = //
254-
name("math.add").input(9., 10.).op();
254+
name("math.add").input(9., 10.).function();
255255
final Object result = op.apply(11., 12.);
256256
assertEquals(23., result);
257257
}
@@ -260,7 +260,7 @@ public void testArity2_IV_OU_match() {
260260
@Test
261261
public void testArity2_IV_OT_match() {
262262
final BiFunction<Double, Double, Double> op = //
263-
name("math.add").input(13., 14.).outType(Double.class).op();
263+
name("math.add").input(13., 14.).outType(Double.class).function();
264264
final double result = op.apply(15., 16.);
265265
assertEquals(31., result, 0.);
266266
}
@@ -271,7 +271,7 @@ public void testArity2_IV_OV_match() {
271271
final String[] s = {"ups", "and", "downs"};
272272
final Object[] o = {"ide", "rogynous", "tream"};
273273
final String[] result = new String[s.length];
274-
Computers.Arity2<String[], Object[], String[]> op = name("test.concat").input(s, o).output(result).op();
274+
Computers.Arity2<String[], Object[], String[]> op = name("test.concat").input(s, o).output(result).computer();
275275
op.compute(s, o, result);
276276
for (int i = 0; i < result.length; i++)
277277
assertEquals(s[i] + o[i], result[i]);

0 commit comments

Comments
 (0)