Skip to content

Commit 071dc89

Browse files
committed
Module: revamp item resolution
Previously, only inputs could be marked resolved or not. But it is useful also to be able to resolve outputs, so that the postprocessing chain can be more intelligent about its actions. So now the API allows resolution of both inputs and outputs.
1 parent cf8aaee commit 071dc89

3 files changed

Lines changed: 93 additions & 12 deletions

File tree

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>scijava-common</artifactId>
13-
<version>2.58.4-SNAPSHOT</version>
13+
<version>2.59.0-SNAPSHOT</version>
1414

1515
<name>SciJava Common</name>
1616
<description>SciJava Common is a shared library for SciJava software. It provides a plugin framework, with an extensible mechanism for service discovery, backed by its own annotation processor, so that plugins can be loaded dynamically. It is used by downstream projects in the SciJava ecosystem, such as ImageJ and SCIFIO.</description>

‎src/main/java/org/scijava/module/AbstractModule.java‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@ public abstract class AbstractModule implements Module {
4848
private final HashMap<String, Object> inputs;
4949
private final HashMap<String, Object> outputs;
5050

51-
/** Table indicating resolved inputs. */
5251
private final HashSet<String> resolvedInputs;
52+
private final HashSet<String> resolvedOutputs;
5353

5454
private MethodRef initializerRef;
5555

5656
public AbstractModule() {
5757
inputs = new HashMap<>();
5858
outputs = new HashMap<>();
5959
resolvedInputs = new HashSet<>();
60+
resolvedOutputs = new HashSet<>();
6061
}
6162

6263
// -- Module methods --
@@ -137,14 +138,33 @@ public void setOutputs(final Map<String, Object> outputs) {
137138
}
138139

139140
@Override
140-
public boolean isResolved(final String name) {
141+
public boolean isInputResolved(final String name) {
141142
return resolvedInputs.contains(name);
142143
}
143144

144145
@Override
145-
public void setResolved(final String name, final boolean resolved) {
146-
if (resolved) resolvedInputs.add(name);
147-
else resolvedInputs.remove(name);
146+
public boolean isOutputResolved(final String name) {
147+
return resolvedOutputs.contains(name);
148+
}
149+
150+
@Override
151+
public void resolveInput(final String name) {
152+
resolvedInputs.add(name);
153+
}
154+
155+
@Override
156+
public void resolveOutput(final String name) {
157+
resolvedOutputs.add(name);
158+
}
159+
160+
@Override
161+
public void unresolveInput(final String name) {
162+
resolvedInputs.remove(name);
163+
}
164+
165+
@Override
166+
public void unresolveOutput(final String name) {
167+
resolvedOutputs.remove(name);
148168
}
149169

150170
// -- Helper methods --

‎src/main/java/org/scijava/module/Module.java‎

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333

3434
import java.util.Map;
3535

36+
import org.scijava.display.DisplayPostprocessor;
37+
import org.scijava.module.process.ModulePostprocessor;
38+
import org.scijava.module.process.ModulePreprocessor;
39+
import org.scijava.widget.InputHarvester;
40+
3641
/**
3742
* A module is an encapsulated piece of functionality with inputs and outputs.
3843
* <p>
@@ -126,15 +131,71 @@ public interface Module extends Runnable {
126131
void setOutputs(Map<String, Object> outputs);
127132

128133
/**
129-
* Gets the resolution status of the input with the given name. A "resolved"
130-
* input is known to have a final, valid value for use with the module.
134+
* Gets the resolution status of the input with the given name.
135+
*
136+
* @see #resolveInput(String)
137+
*/
138+
boolean isInputResolved(String name);
139+
140+
/**
141+
* Gets the resolution status of the output with the given name.
142+
*
143+
* @see #resolveOutput(String)
144+
*/
145+
boolean isOutputResolved(String name);
146+
147+
/**
148+
* Marks the input with the given name as resolved. A "resolved" input is
149+
* known to have a final, valid value for use with the module.
150+
* <p>
151+
* {@link ModulePreprocessor}s in the module execution chain that populate
152+
* input values (e.g. {@link InputHarvester} plugins) will typically skip over
153+
* inputs which have already been resolved.
154+
* </p>
155+
*/
156+
void resolveInput(String name);
157+
158+
/**
159+
* Marks the output with the given name as resolved. A "resolved" output has
160+
* been handled by the framework somehow, typically displayed to the user.
161+
* <p>
162+
* {@link ModulePostprocessor}s in the module execution chain that handle
163+
* output values (e.g. the {@link DisplayPostprocessor}) will typically skip
164+
* over outputs which have already been resolved.
165+
* </p>
166+
*/
167+
void resolveOutput(String name);
168+
169+
/**
170+
* Marks the input with the given name as unresolved.
171+
*
172+
* @see #resolveInput(String)
131173
*/
132-
boolean isResolved(String name);
174+
void unresolveInput(String name);
175+
176+
/**
177+
* Marks the output with the given name as unresolved.
178+
*
179+
* @see #resolveOutput(String)
180+
*/
181+
void unresolveOutput(String name);
182+
183+
// -- Deprecated --
184+
185+
/** @deprecated Use {@link #isInputResolved(String)} instead. */
186+
@Deprecated
187+
default boolean isResolved(final String name) {
188+
return isInputResolved(name);
189+
}
133190

134191
/**
135-
* Sets the resolution status of the input with the given name. A "resolved"
136-
* input is known to have a final, valid value for use with the module.
192+
* @deprecated Use {@link #resolveInput(String)} and
193+
* {@link #unresolveInput(String)} instead.
137194
*/
138-
void setResolved(String name, boolean resolved);
195+
@Deprecated
196+
default void setResolved(final String name, final boolean resolved) {
197+
if (resolved) resolveInput(name);
198+
else unresolveInput(name);
199+
}
139200

140201
}

0 commit comments

Comments
 (0)