Skip to content

Commit e3ef2a0

Browse files
gselzerctrueden
authored andcommitted
Fix priority bug
The matcher was sorting ops from lowest to highest priority, which is flipped. We want highest to lowest priority, which is how it now works.
1 parent 1146536 commit e3ef2a0

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/main/java/org/scijava/ops/matcher/DefaultOpTypeMatchingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public List<OpCandidate> filterMatches(final List<OpCandidate> candidates) {
113113
// List of valid candidates needs to be sorted according to priority.
114114
// This is used as an optimization in order to not look at ops with
115115
// lower priority than the already found one.
116-
validCandidates.sort((c1, c2) -> Double.compare(c1.opInfo().priority(), c2.opInfo().priority()));
116+
validCandidates.sort((c1, c2) -> Double.compare(c2.opInfo().priority(), c1.opInfo().priority()));
117117

118118
List<OpCandidate> matches;
119119
matches = filterMatches(validCandidates, (cand) -> typesPerfectMatch(cand));

src/test/java/org/scijava/ops/OpPriorityTest.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,39 @@
2929

3030
package org.scijava.ops;
3131
import static org.junit.Assert.assertTrue;
32+
3233
import java.util.function.BiFunction;
3334

3435
import org.junit.Test;
35-
import org.scijava.param.ValidityException;
36+
import org.scijava.core.Priority;
37+
import org.scijava.ops.core.Op;
38+
import org.scijava.ops.core.Source;
3639
import org.scijava.ops.types.Nil;
40+
import org.scijava.param.Parameter;
41+
import org.scijava.param.ValidityException;
42+
import org.scijava.plugin.Plugin;
43+
import org.scijava.struct.ItemIO;
3744

3845
public class OpPriorityTest extends AbstractTestEnvironment {
46+
47+
@Plugin(type = Op.class, name = "test.priority", priority = Priority.HIGH)
48+
@Parameter(key = "result", type = ItemIO.OUTPUT)
49+
private static final class testDouble implements Source<Number>{
50+
@Override
51+
public Number create() {
52+
return new Double(0.0);
53+
}
54+
}
55+
56+
@Plugin(type = Op.class, name = "test.priority", priority = Priority.LOW)
57+
@Parameter(key = "result", type = ItemIO.OUTPUT)
58+
private static final class testFloat implements Source<Number>{
59+
@Override
60+
public Number create() {
61+
return new Float(0.0);
62+
}
63+
}
64+
3965

4066
Nil<Double> nilDouble = new Nil<Double>() {
4167
};
@@ -52,4 +78,12 @@ public void testOpCollection() throws ValidityException {
5278
// The found op is assumed to come from the MathOpCollection
5379
assertTrue(divFunction.getClass().getName().contains("MathOpCollection$$Lambda"));
5480
}
81+
82+
@Test
83+
public void testOpPriority() {
84+
85+
Source<Number> testFunc = ops().findOp("test.priority", new Nil<Source<Number>>() {}, new Nil[] {}, new Nil<Number>() {});
86+
Number x = testFunc.create();
87+
assertTrue(x instanceof Double);
88+
}
5589
}

0 commit comments

Comments
 (0)