Skip to content

Commit 8b07642

Browse files
committed
Remove OpHistory Op logging API.
It's not necessary, as RichOp now does these things as well. Let's lean into RichOp
1 parent e73b8e7 commit 8b07642

File tree

6 files changed

+50
-80
lines changed

6 files changed

+50
-80
lines changed

scijava-ops-api/src/main/java/org/scijava/ops/api/OpHistory.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,8 @@ static OpHistory getOpHistory() {
7777
*/
7878
List<RichOp<?>> executionsUpon(Object o);
7979

80-
/**
81-
* Returns the hierarchy of {@link OpInfo}s describing the dependency tree of
82-
* the {@link Object} {@code op}.
83-
*
84-
* @param op the {@link Object} returned by a matching call. NB {@code op}
85-
* <b>must</b> be the {@link Object} returned by the outermost
86-
* matching call, as the dependency {@link Object}s are not recorded.
87-
* @return the {@link InfoTree} describing the dependency tree
88-
*/
89-
InfoTree infoTree(Object op);
90-
91-
default String signatureOf(Object op) {
92-
return infoTree(op).signature();
93-
}
94-
9580
// -- HISTORY MAINTENANCE API -- //
9681

97-
/**
98-
* Logs the creation of {@link RichOp}
99-
*
100-
* @param op the {@link RichOp} containing relevant information
101-
*/
102-
void logOp(RichOp<?> op);
103-
10482
/**
10583
* Logs the {@link Object} output of the {@link RichOp} {@code op}.
10684
*

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,38 @@ public static <T> RichOp<T> rich(T op) {
6666
return (RichOp<T>) op;
6767
}
6868

69+
/**
70+
* Convenience function for getting the {@link InfoTree} behind {@code op}
71+
*
72+
* @param op the Op
73+
* @return the {@link InfoTree} of {@code op}
74+
* @throws IllegalArgumentException if {@code op} is not an Op
75+
*/
76+
public static InfoTree infoTree(Object op) {
77+
return rich(op).instance().infoTree();
78+
}
79+
6980
/**
7081
* Convenience function for getting the {@link OpInfo} of {@code op}
7182
*
7283
* @param op the Op
7384
* @return the {@link OpInfo} that generated {@code op}
74-
* @param <T> the type of {@code op}
7585
* @throws IllegalArgumentException if {@code op} is not an Op
7686
*/
77-
public static <T> OpInfo info(T op) {
78-
return rich(op).instance().infoTree().info();
87+
public static OpInfo info(Object op) {
88+
return infoTree(op).info();
89+
}
90+
91+
/**
92+
* Convenience function for getting the signature of {@code op}
93+
*
94+
* @param op the Op
95+
* @return the signature of {@code op}, which can be used to completely
96+
* restore {@code op}
97+
* @throws IllegalArgumentException if {@code op} is not an Op
98+
*/
99+
public static String signature(Object op) {
100+
return infoTree(op).signature();
79101
}
80102

81103
}

scijava-ops-engine/src/main/java/org/scijava/ops/engine/impl/DefaultOpHistory.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ public class DefaultOpHistory implements OpHistory {
6464

6565
// -- DATA STRCUTURES -- //
6666

67-
/**
68-
* {@link Map} responsible for recording the {@link InfoTree} of
69-
* {@link OpInfo}s involved to produce the result of a particular matching
70-
* call
71-
*/
72-
private final Map<RichOp<?>, InfoTree> dependencyChain = new WeakHashMap<>();
73-
7467
private final Map<Object, List<RichOp<?>>> mutationMap = new WeakHashMap<>();
7568

7669
// -- USER API -- //
@@ -89,22 +82,8 @@ public List<RichOp<?>> executionsUpon(Object o) {
8982
return mutationMap.getOrDefault(o, Collections.emptyList());
9083
}
9184

92-
@Override
93-
public InfoTree infoTree(Object op) {
94-
if (op instanceof RichOp<?>) {
95-
return dependencyChain.get(op);
96-
}
97-
throw new IllegalArgumentException("Object " + op +
98-
" is not an Op known to this OpHistory!");
99-
}
100-
10185
// -- HISTORY MAINTENANCE API -- //
10286

103-
@Override
104-
public void logOp(RichOp<?> op) {
105-
dependencyChain.put(op, op.infoTree());
106-
}
107-
10887
@Override
10988
public void logOutput(RichOp<?> op, Object output) {
11089
if (!mutationMap.containsKey(output)) updateList(output);

scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/impl/AbstractRichOp.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ public AbstractRichOp(final OpInstance<T> instance, final OpEnvironment env,
6363
this.instance = instance;
6464
this.env = env;
6565
this.conditions = conditions;
66-
67-
this.env.history().logOp(this);
6866
}
6967

7068
@Override

scijava-ops-engine/src/test/java/org/scijava/ops/engine/InfoTreeGeneratorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.scijava.ops.api.InfoTree;
1212
import org.scijava.ops.api.OpEnvironment;
1313
import org.scijava.ops.api.OpInfo;
14+
import org.scijava.ops.api.Ops;
1415
import org.scijava.ops.spi.OpCollection;
1516
import org.scijava.ops.spi.OpField;
1617
import org.scijava.priority.Priority;
@@ -33,7 +34,7 @@ public void testMultipleValidInfoTreeGenerators() {
3334
// and by our dummy generator
3435
var op = ops.unary("test.infoTreeGeneration").inType(Double.class).outType(
3536
Double.class).function();
36-
String signature = ops.history().signatureOf(op);
37+
String signature = Ops.signature(op);
3738
// Run treeFromID to make sure our generator doesn't run
3839
var infoTree = ops.treeFromID(signature);
3940
// Assert non-null output

scijava-ops-engine/src/test/java/org/scijava/ops/engine/impl/ProvenanceTest.java

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,13 @@
2929

3030
package org.scijava.ops.engine.impl;
3131

32-
import java.util.ArrayList;
33-
import java.util.Arrays;
34-
import java.util.Iterator;
35-
import java.util.List;
36-
import java.util.function.Function;
37-
3832
import org.junit.jupiter.api.Assertions;
3933
import org.junit.jupiter.api.BeforeAll;
4034
import org.junit.jupiter.api.Test;
4135
import org.scijava.collections.ObjectArray;
4236
import org.scijava.function.Computers;
4337
import org.scijava.function.Producer;
44-
import org.scijava.ops.api.Hints;
45-
import org.scijava.ops.api.InfoTree;
46-
import org.scijava.ops.api.OpEnvironment;
47-
import org.scijava.ops.api.OpInfo;
48-
import org.scijava.ops.api.RichOp;
38+
import org.scijava.ops.api.*;
4939
import org.scijava.ops.engine.AbstractTestEnvironment;
5040
import org.scijava.ops.engine.BaseOpHints;
5141
import org.scijava.ops.engine.adapt.functional.ComputersToFunctionsViaFunction;
@@ -55,14 +45,16 @@
5545
import org.scijava.ops.engine.matcher.simplify.PrimitiveArraySimplifiers;
5646
import org.scijava.ops.engine.matcher.simplify.PrimitiveLossReporters;
5747
import org.scijava.ops.engine.matcher.simplify.PrimitiveSimplifiers;
58-
import org.scijava.ops.spi.Op;
59-
import org.scijava.ops.spi.OpClass;
60-
import org.scijava.ops.spi.OpCollection;
61-
import org.scijava.ops.spi.OpDependency;
62-
import org.scijava.ops.spi.OpField;
48+
import org.scijava.ops.spi.*;
6349
import org.scijava.priority.Priority;
6450
import org.scijava.types.Nil;
6551

52+
import java.util.ArrayList;
53+
import java.util.Arrays;
54+
import java.util.Iterator;
55+
import java.util.List;
56+
import java.util.function.Function;
57+
6658
public class ProvenanceTest extends AbstractTestEnvironment implements
6759
OpCollection
6860
{
@@ -71,11 +63,11 @@ public class ProvenanceTest extends AbstractTestEnvironment implements
7163
public static void AddNeededOps() {
7264
ops.register(new ProvenanceTest());
7365
ops.register(new MapperFunc());
74-
ops.register(new FunctionToArrays());
66+
ops.register(new FunctionToArrays<>());
7567
ops.register(new PrimitiveSimplifiers());
76-
ops.register(new PrimitiveArraySimplifiers());
68+
ops.register(new PrimitiveArraySimplifiers<>());
7769
ops.register(new PrimitiveLossReporters());
78-
ops.register(new CopyOpCollection());
70+
ops.register(new CopyOpCollection<>());
7971
ops.register(new CreateOpCollection());
8072
Object[] adaptors = objsFromNoArgConstructors(
8173
ComputersToFunctionsViaFunction.class.getDeclaredClasses());
@@ -151,7 +143,7 @@ public void testProvenance() {
151143
List<RichOp<?>> executionsUpon = ops.history().executionsUpon(s);
152144
Assertions.assertEquals(1, executionsUpon.size());
153145
// Assert only one info in the execution hierarchy
154-
InfoTree executionHierarchy = ops.history().infoTree(executionsUpon.get(0));
146+
InfoTree executionHierarchy = Ops.infoTree(executionsUpon.get(0));
155147
Assertions.assertEquals(0, executionHierarchy.dependencies().size());
156148
OpInfo info = executionHierarchy.info();
157149
Assertions.assertTrue(info.implementationName().contains(this.getClass()
@@ -180,15 +172,15 @@ public void testPriorityProvenance() {
180172
List<RichOp<?>> history2 = ops.history().executionsUpon(out2);
181173

182174
Assertions.assertEquals(1, history1.size());
183-
InfoTree opExecutionChain = ops.history().infoTree(history1.get(0));
175+
InfoTree opExecutionChain = Ops.infoTree(history1.get(0));
184176
Assertions.assertEquals(0, opExecutionChain.dependencies().size());
185177
String expected =
186178
"public final java.util.function.Function org.scijava.ops.engine.impl.ProvenanceTest.baz";
187179
Assertions.assertEquals(expected, opExecutionChain.info()
188180
.getAnnotationBearer().toString());
189181

190182
Assertions.assertEquals(1, history2.size());
191-
opExecutionChain = ops.history().infoTree(history2.get(0));
183+
opExecutionChain = Ops.infoTree(history2.get(0));
192184
Assertions.assertEquals(0, opExecutionChain.dependencies().size());
193185
expected =
194186
"public final java.util.function.Function org.scijava.ops.engine.impl.ProvenanceTest.bar";
@@ -221,7 +213,7 @@ public void testMappingInfoTree() {
221213
.input(array).outType(Thing.class).function();
222214

223215
// Get the InfoTree associated with the above call
224-
InfoTree tree = ops.history().infoTree(mapper);
216+
InfoTree tree = Ops.infoTree(mapper);
225217

226218
// Assert the mapper is in the tree
227219
Iterator<OpInfo> mapperInfos = ops.infos("test.provenanceMapper")
@@ -275,7 +267,7 @@ public void testDependencylessOpRecoveryFromString() {
275267
.outType(Thing.class) //
276268
.function();
277269
// Get the signature from the Op
278-
String signature = ops.history().signatureOf(mapper);
270+
String signature = Ops.signature(mapper);
279271
// Generate the Op from the signature and an Op type
280272
Nil<Function<Double, Thing>> specialType = new Nil<>() {};
281273
Function<Double, Thing> actual = ops //
@@ -298,7 +290,7 @@ public void testOpWithDependencyRecoveryFromString() {
298290
.outType(Thing.class) //
299291
.function();
300292
// Get the signature from the Op
301-
String signature = ops.history().signatureOf(mapper);
293+
String signature = Ops.signature(mapper);
302294
// Generate the Op from the signature and an Op type
303295
Nil<Function<Double, Thing>> specialType = new Nil<>() {};
304296
Function<Double, Thing> actual = ops //
@@ -321,7 +313,7 @@ public void testAdaptationRecoveryFromString() {
321313
.outType(Thing[].class) //
322314
.function();
323315
// Get the signature from the Op
324-
String signature = ops.history().signatureOf(f);
316+
String signature = Ops.signature(f);
325317
// Generate the Op from the signature and an Op type
326318
Nil<Function<Double[], Thing[]>> special = new Nil<>() {};
327319
Function<Double[], Thing[]> actual = ops. //
@@ -344,7 +336,7 @@ public void testAdaptedOpWithDependencies() {
344336
.outType(Thing[].class) //
345337
.function();
346338
// Get the signature from the Op
347-
String signature = ops.history().signatureOf(f);
339+
String signature = Ops.signature(f);
348340
// Generate the Op from the signature and an Op type
349341
Nil<Function<Double[][], Thing[]>> special = new Nil<>() {};
350342
Function<Double[][], Thing[]> actual = ops //
@@ -369,7 +361,7 @@ public void testSimplificationRecovery() {
369361
{}) //
370362
.computer();
371363
// Get the signature from the Op
372-
String signature = ops.history().signatureOf(c);
364+
String signature = Ops.signature(c);
373365
// Generate the Op from the signature and an Op type
374366
Nil<Computers.Arity1<ObjectArray<Number>, ObjectArray<Number>>> special =
375367
new Nil<>()
@@ -401,7 +393,7 @@ public void testFocusedRecovery() {
401393
.outType(Integer[].class) //
402394
.computer();
403395
// Get the signature from the Op
404-
String signature = ops.history().signatureOf(c);
396+
String signature = Ops.signature(c);
405397
// Generate the Op from the signature and an Op typ
406398
Nil<Computers.Arity1<Integer[], Integer[]>> special = new Nil<>() {};
407399
Computers.Arity1<Integer[], Integer[]> fromString = ops.opFromSignature(
@@ -428,7 +420,7 @@ public void testSimplificationAdaptationRecovery() {
428420
.outType(Integer[].class) //
429421
.function();
430422
// Get the signature from the Op
431-
String signature = ops.history().signatureOf(c);
423+
String signature = Ops.signature(c);
432424
// Generate the Op from the signature and the Op type
433425
Nil<Function<Integer[], Integer[]>> special = new Nil<>() {};
434426
Function<Integer[], Integer[]> fromString = ops //
@@ -456,7 +448,7 @@ public void testAdaptationWithDependencies() {
456448
.outType(Double[].class) //
457449
.function();
458450
// Get the signature from the Op
459-
String signature = ops.history().signatureOf(f);
451+
String signature = Ops.signature(f);
460452
// Generate the Op from the signature and the Op type
461453
Nil<Function<Double[], Double[]>> special = new Nil<>() {};
462454
Function<Double[], Double[]> actual = ops //

0 commit comments

Comments
 (0)