Skip to content

Commit 54e4fb3

Browse files
committed
Push default WrapperService behavior to iface
Thanks, Java 8.
1 parent 2c50d02 commit 54e4fb3

File tree

2 files changed

+22
-43
lines changed

2 files changed

+22
-43
lines changed

src/main/java/org/scijava/plugin/AbstractWrapperService.java

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
package org.scijava.plugin;
3333

34-
import org.scijava.log.LogService;
35-
3634
/**
3735
* Abstract base class for {@link WrapperService}s.
3836
*
@@ -43,44 +41,5 @@
4341
public abstract class AbstractWrapperService<DT, PT extends WrapperPlugin<DT>>
4442
extends AbstractTypedService<DT, PT> implements WrapperService<DT, PT>
4543
{
46-
47-
@Parameter(required = false)
48-
private LogService log;
49-
50-
// -- WrapperService methods --
51-
52-
@Override
53-
public <D extends DT> PT create(final D data) {
54-
final PT instance = findWrapper(data);
55-
if (instance != null) instance.set(data);
56-
return instance;
57-
}
58-
59-
// -- Service methods --
60-
61-
@Override
62-
public void initialize() {
63-
if (log != null) {
64-
log.debug("Found " + getPlugins().size() + " " +
65-
getPluginType().getSimpleName() + " plugins.");
66-
}
67-
}
68-
69-
// -- Typed methods --
70-
71-
@Override
72-
public boolean supports(final DT data) {
73-
return findWrapper(data) != null;
74-
}
75-
76-
// -- Helper methods --
77-
78-
private <D extends DT> PT findWrapper(final D data) {
79-
for (final PluginInfo<PT> plugin : getPlugins()) {
80-
final PT instance = pluginService().createInstance(plugin);
81-
if (instance != null && instance.supports(data)) return instance;
82-
}
83-
return null;
84-
}
85-
44+
// NB: No implementation needed.
8645
}

src/main/java/org/scijava/plugin/WrapperService.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ public interface WrapperService<DT, PT extends WrapperPlugin<DT>> extends
6262
* @return An appropriate plugin instance, or null if the data is not
6363
* compatible with any available plugin.
6464
*/
65-
<D extends DT> PT create(D data);
65+
default <D extends DT> PT create(final D data) {
66+
final PT instance = find(data);
67+
if (instance != null) instance.set(data);
68+
return instance;
69+
}
6670

71+
// -- Service methods --
72+
73+
@Override
74+
default void initialize() {
75+
if (log() != null) {
76+
log().debug("Found " + getPlugins().size() + " " +
77+
getPluginType().getSimpleName() + " plugins.");
78+
}
79+
}
80+
81+
// -- Typed methods --
82+
83+
@Override
84+
default boolean supports(final DT data) {
85+
return find(data) != null;
86+
}
6787
}

0 commit comments

Comments
 (0)