22package org .scijava .ops .engine .impl ;
33
44import java .util .ArrayList ;
5+ import java .util .Collections ;
6+ import java .util .HashSet ;
57import java .util .List ;
68import java .util .Map ;
9+ import java .util .Set ;
710import java .util .WeakHashMap ;
811
912import org .scijava .ops .api .InfoChain ;
13+ import org .scijava .ops .api .OpExecution ;
1014import org .scijava .ops .api .OpHistory ;
1115import org .scijava .ops .api .OpInfo ;
1216import org .scijava .ops .api .RichOp ;
@@ -39,8 +43,9 @@ public class DefaultOpHistory extends AbstractService implements OpHistory {
3943 // -- DATA STRCUTURES -- //
4044
4145 /**
42- * {@link Map} responsible for recording the {@link InfoChain} of {@link OpInfo}s
43- * involved to produce the result of a particular matching call
46+ * {@link Map} responsible for recording the {@link InfoChain} of
47+ * {@link OpInfo}s involved to produce the result of a particular matching
48+ * call
4449 */
4550 private final Map <RichOp <?>, InfoChain > dependencyChain = new WeakHashMap <>();
4651
@@ -59,7 +64,7 @@ public class DefaultOpHistory extends AbstractService implements OpHistory {
5964 public List <RichOp <?>> executionsUpon (Object o ) {
6065 if (o .getClass ().isPrimitive ()) throw new IllegalArgumentException (
6166 "Cannot determine the executions upon a primitive as they are passed by reference!" );
62- return mutationMap .get ( o );
67+ return mutationMap .getOrDefault ( o , Collections . emptyList () );
6368 }
6469
6570 @ Override
@@ -69,28 +74,15 @@ public InfoChain opExecutionChain(Object op) {
6974
7075 // -- HISTORY MAINTENANCE API -- //
7176
72- /**
73- * Logs an Op execution in the history
74- * <p>
75- * TODO: It would be nice if different Objects returned different Objects with
76- * the same hash code would hash differently. For example, if two Ops return a
77- * {@link Double} of the same value, they will appear as the same Object, and
78- * asking for the execution history on either of the {@link Object}s will
79- * suggest that both executions mutated both {@link Object}s. This would
80- * really hamper the simplicity of the implementation, however.
81- *
82- * @param op the {@link RichOp} being executed
83- * @param output the output of the Op execution
84- */
8577 @ Override
86- public void addExecution (RichOp <?> op , Object output ) {
87- if (!mutationMap .containsKey (output )) updateList (output );
88- resolveExecution (op , output );
78+ public void logOp (RichOp <?> op ) {
79+ dependencyChain .put (op , op .infoChain ());
8980 }
9081
9182 @ Override
92- public void logOp (RichOp <?> op ) {
93- dependencyChain .put (op , op .infoChain ());
83+ public void logOutput (RichOp <?> op , Object output ) {
84+ if (!mutationMap .containsKey (output )) updateList (output );
85+ resolveExecution (op , output );
9486 }
9587
9688 // -- HELPER METHODS -- //
0 commit comments