Skip to content

Commit 9bab076

Browse files
committed
RunService: move default method impls to iface
1 parent 16d4289 commit 9bab076

File tree

2 files changed

+36
-54
lines changed

2 files changed

+36
-54
lines changed

src/main/java/org/scijava/run/DefaultRunService.java

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@
3131

3232
package org.scijava.run;
3333

34-
import java.lang.reflect.InvocationTargetException;
35-
import java.util.Map;
36-
37-
import org.scijava.log.LogService;
3834
import org.scijava.plugin.AbstractHandlerService;
39-
import org.scijava.plugin.Parameter;
4035
import org.scijava.plugin.Plugin;
4136
import org.scijava.service.Service;
4237

@@ -49,50 +44,5 @@
4944
public class DefaultRunService extends
5045
AbstractHandlerService<Object, CodeRunner> implements RunService
5146
{
52-
53-
@Parameter
54-
private LogService log;
55-
56-
// -- RunService methods --
57-
58-
@Override
59-
public void run(final Object code, final Object... args)
60-
throws InvocationTargetException
61-
{
62-
for (final CodeRunner runner : getInstances()) {
63-
if (runner.supports(code)) {
64-
runner.run(code, args);
65-
return;
66-
}
67-
}
68-
throw new IllegalArgumentException("Unknown code type: " + code);
69-
}
70-
71-
@Override
72-
public void run(final Object code, final Map<String, Object> inputMap)
73-
throws InvocationTargetException
74-
{
75-
for (final CodeRunner runner : getInstances()) {
76-
if (runner.supports(code)) {
77-
runner.run(code, inputMap);
78-
return;
79-
}
80-
}
81-
throw new IllegalArgumentException("Unknown code type: " + code);
82-
}
83-
84-
// -- PTService methods --
85-
86-
@Override
87-
public Class<CodeRunner> getPluginType() {
88-
return CodeRunner.class;
89-
}
90-
91-
// -- Typed methods --
92-
93-
@Override
94-
public Class<Object> getType() {
95-
return Object.class;
96-
}
97-
47+
// NB: No implementation needed.
9848
}

src/main/java/org/scijava/run/RunService.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,45 @@ public interface RunService extends
5050
* Executes the given code using the most appropriate handler, passing the
5151
* specified arguments as inputs.
5252
*/
53-
void run(Object code, Object... args) throws InvocationTargetException;
53+
default void run(final Object code, final Object... args)
54+
throws InvocationTargetException
55+
{
56+
for (final CodeRunner runner : getInstances()) {
57+
if (runner.supports(code)) {
58+
runner.run(code, args);
59+
return;
60+
}
61+
}
62+
throw new IllegalArgumentException("Unknown code type: " + code);
63+
}
5464

5565
/**
5666
* Executes the given code using the most appropriate handler, passing the
5767
* arguments in the specified map as inputs.
5868
*/
59-
void run(Object code, Map<String, Object> inputMap)
60-
throws InvocationTargetException;
69+
default void run(final Object code, final Map<String, Object> inputMap)
70+
throws InvocationTargetException
71+
{
72+
for (final CodeRunner runner : getInstances()) {
73+
if (runner.supports(code)) {
74+
runner.run(code, inputMap);
75+
return;
76+
}
77+
}
78+
throw new IllegalArgumentException("Unknown code type: " + code);
79+
}
6180

81+
// -- PTService methods --
82+
83+
@Override
84+
default Class<CodeRunner> getPluginType() {
85+
return CodeRunner.class;
86+
}
87+
88+
// -- Typed methods --
89+
90+
@Override
91+
default Class<Object> getType() {
92+
return Object.class;
93+
}
6294
}

0 commit comments

Comments
 (0)