Skip to content

Commit 856d928

Browse files
committed
Make InfoTreeGenerator a Prioritized
This allows us to sort them, and find the highest-priority
1 parent 1f3cb53 commit 856d928

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

‎scijava/scijava-ops-engine/src/main/java/org/scijava/ops/engine/InfoTreeGenerator.java‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636

3737
import org.scijava.ops.api.InfoTree;
3838
import org.scijava.ops.api.OpInfo;
39+
import org.scijava.priority.Prioritized;
40+
import org.scijava.priority.Priority;
3941

40-
public interface InfoTreeGenerator {
42+
public interface InfoTreeGenerator extends Prioritized<InfoTreeGenerator> {
4143

4244

4345
/**
@@ -68,13 +70,11 @@ static InfoTreeGenerator findSuitableGenerator(String signature,
6870
{
6971
List<InfoTreeGenerator> suitableGenerators = generators.stream() //
7072
.filter(g -> g.canGenerate(signature)) //
73+
.sorted() //
7174
.collect(Collectors.toList());
72-
if (suitableGenerators.size() == 0) throw new IllegalArgumentException(
75+
if (suitableGenerators.isEmpty()) throw new IllegalArgumentException(
7376
"No InfoTreeGenerator in given collection " + generators +
7477
" is able to reify signature " + signature);
75-
if (suitableGenerators.size() > 1) throw new IllegalArgumentException(
76-
"Signature " + signature +
77-
" is able to be reified by multiple generators: " + suitableGenerators);
7878
return suitableGenerators.get(0);
7979
}
8080

@@ -90,8 +90,8 @@ static InfoTree generateDependencyTree(String subsignature,
9090
* Finds the subsignature in {@link String} {@code signature}. The
9191
* subsignature is assumed to start at index {@code start}.
9292
*
93-
* @param signature
94-
* @param start
93+
* @param signature the signature containing a subsignature
94+
* @param start the index where the subsignature starts
9595
* @return a signature contained withing {@code signature}
9696
*/
9797
static String subSignatureFrom(String signature, int start) {
@@ -103,8 +103,7 @@ static String subSignatureFrom(String signature, int start) {
103103
else if (ch == InfoTree.DEP_END_DELIM) {
104104
depth--;
105105
if (depth == 0) {
106-
int depsEnd = i;
107-
return signature.substring(start, depsEnd + 1);
106+
return signature.substring(start, i + 1);
108107
}
109108
}
110109
}
@@ -124,4 +123,8 @@ else if (ch == InfoTree.DEP_END_DELIM) {
124123
*/
125124
boolean canGenerate(String signature);
126125

126+
@Override
127+
default double getPriority() {
128+
return Priority.NORMAL;
129+
}
127130
}

0 commit comments

Comments
 (0)