Skip to content

Commit 46a6f50

Browse files
committed
IOService: move default method impls to iface
1 parent 84be9d1 commit 46a6f50

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

src/main/java/org/scijava/io/DefaultIOService.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,6 @@ public final class DefaultIOService
6060

6161
// -- IOService methods --
6262

63-
@Override
64-
public IOPlugin<?> getOpener(final String source) {
65-
for (final IOPlugin<?> handler : getInstances()) {
66-
if (handler.supportsOpen(source)) return handler;
67-
}
68-
return null;
69-
}
70-
71-
@Override
72-
public <D> IOPlugin<D> getSaver(final D data, final String destination) {
73-
for (final IOPlugin<?> handler : getInstances()) {
74-
if (handler.supportsSave(data, destination)) {
75-
@SuppressWarnings("unchecked")
76-
final IOPlugin<D> typedHandler = (IOPlugin<D>) handler;
77-
return typedHandler;
78-
}
79-
}
80-
return null;
81-
}
82-
8363
@Override
8464
public Object open(final String source) throws IOException {
8565
final IOPlugin<?> opener = getOpener(source);
@@ -102,18 +82,4 @@ public void save(final Object data, final String destination)
10282
eventService.publish(new DataSavedEvent(destination, data));
10383
}
10484
}
105-
106-
// -- HandlerService methods --
107-
108-
@Override
109-
@SuppressWarnings({ "rawtypes", "unchecked" })
110-
public Class<IOPlugin<?>> getPluginType() {
111-
return (Class) IOPlugin.class;
112-
}
113-
114-
@Override
115-
public Class<String> getType() {
116-
return String.class;
117-
}
118-
11985
}

src/main/java/org/scijava/io/IOService.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,27 @@ public interface IOService extends HandlerService<String, IOPlugin<?>>,
5151
* Gets the most appropriate {@link IOPlugin} for opening data from the given
5252
* source.
5353
*/
54-
IOPlugin<?> getOpener(String source);
54+
default IOPlugin<?> getOpener(final String source) {
55+
for (final IOPlugin<?> handler : getInstances()) {
56+
if (handler.supportsOpen(source)) return handler;
57+
}
58+
return null;
59+
}
5560

5661
/**
5762
* Gets the most appropriate {@link IOPlugin} for saving data to the given
5863
* destination.
5964
*/
60-
<D> IOPlugin<D> getSaver(D data, String destination);
65+
default <D> IOPlugin<D> getSaver(final D data, final String destination) {
66+
for (final IOPlugin<?> handler : getInstances()) {
67+
if (handler.supportsSave(data, destination)) {
68+
@SuppressWarnings("unchecked")
69+
final IOPlugin<D> typedHandler = (IOPlugin<D>) handler;
70+
return typedHandler;
71+
}
72+
}
73+
return null;
74+
}
6175

6276
/**
6377
* Loads data from the given source. For extensibility, the nature of the
@@ -91,4 +105,16 @@ public interface IOService extends HandlerService<String, IOPlugin<?>>,
91105
*/
92106
void save(Object data, String destination) throws IOException;
93107

108+
// -- HandlerService methods --
109+
110+
@Override
111+
@SuppressWarnings({ "rawtypes", "unchecked" })
112+
default Class<IOPlugin<?>> getPluginType() {
113+
return (Class) IOPlugin.class;
114+
}
115+
116+
@Override
117+
default Class<String> getType() {
118+
return String.class;
119+
}
94120
}

0 commit comments

Comments
 (0)