Skip to content

Commit e2647a1

Browse files
gselzerctrueden
authored andcommitted
Refactor ManualOpCandidate into constructor
1 parent 5f65b44 commit e2647a1

3 files changed

Lines changed: 17 additions & 37 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import java.lang.reflect.Type;
3333
import java.lang.reflect.TypeVariable;
34+
import java.util.HashMap;
3435
import java.util.List;
3536
import java.util.Map;
3637

@@ -43,10 +44,10 @@
4344

4445
/**
4546
* Container class for a possible operation match between an {@link OpRef} and
46-
* an {@link OpInfo}, as computed by the {@link OpMatcher}.
47+
* an {@link OpInfo}.
4748
*
4849
* @author Curtis Rueden
49-
* @see OpMatcher
50+
* @author Gabriel Selzer
5051
*/
5152
public class OpCandidate {
5253

@@ -89,6 +90,10 @@ public OpCandidate(final OpEnvironment env, final OpRef ref, final OpInfo info,
8990
this.reifiedType = getReifiedType(ref, info, typeVarAssigns);
9091
}
9192

93+
public OpCandidate(final OpEnvironment env, final OpRef ref, final OpInfo info) {
94+
this(env, ref, info, typeVarAssignsFromRefAndInfo(ref, info));
95+
}
96+
9297
public static Type getReifiedType(OpRef ref, OpInfo info, Map<TypeVariable<?>, Type> typeVarAssigns) {
9398
Type exactSuperType = Types.getExactSuperType(info.opType(), Types.raw(ref.getType()));
9499
return Types.mapVarToTypes(exactSuperType, typeVarAssigns);
@@ -237,4 +242,13 @@ public Object createOp(List<?> dependencies)
237242
return createOpInstance(dependencies).object();
238243
}
239244

245+
// -- Helper methods -- //
246+
private static Map<TypeVariable<?>, Type> typeVarAssignsFromRefAndInfo(final OpRef ref, final OpInfo info) {
247+
Map<TypeVariable<?>, Type> typeVarAssigns = new HashMap<>();
248+
if (!ref.typesMatch(info.opType(), typeVarAssigns))
249+
throw new IllegalArgumentException(
250+
"OpInfo " + info + " cannot satisfy the requirements contained within OpRef " + ref);
251+
return typeVarAssigns;
252+
}
253+
240254
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,7 @@ private MatchingConditions insertCacheHit(final OpRef ref, final Hints hints,
353353
MatchingConditions conditions = MatchingConditions.from(ref, hints);
354354

355355
// create new OpCandidate from ref and info
356-
OpCandidate candidate = new ManualOpCandidate(this, ref, info,
357-
this.matcher);
356+
OpCandidate candidate = new OpCandidate(this, ref, info);
358357

359358
instantiateAndCache(conditions, candidate);
360359

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

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

0 commit comments

Comments
 (0)