Skip to content

Commit 2c50d02

Browse files
committed
TypedService: add a way to find the best plugin
1 parent 23aada3 commit 2c50d02

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,24 @@
5252
public interface TypedService<DT, PT extends TypedPlugin<DT>> extends
5353
PTService<PT>, Typed<DT>
5454
{
55-
// NB: Marker interface.
55+
56+
/**
57+
* Gets a new instance of the highest priority plugin managed by this service
58+
* which supports the given data object according to the {@link Typed}
59+
* interface.
60+
* <p>
61+
* Note that this newly created plugin instance will <em>not</em> actually be
62+
* injected with the given data object!
63+
* </p>
64+
*
65+
* @see HandlerService#getHandler(Object)
66+
* @see WrapperService#create(Object)
67+
*/
68+
default PT find(final DT data) {
69+
for (final PluginInfo<PT> plugin : getPlugins()) {
70+
final PT instance = pluginService().createInstance(plugin);
71+
if (instance != null && instance.supports(data)) return instance;
72+
}
73+
return null;
74+
}
5675
}

0 commit comments

Comments
 (0)