Skip to content

Commit 4ab6b51

Browse files
committed
IOPlugin: push default method impls to iface
Thank you Java 8.
1 parent 6c190de commit 4ab6b51

File tree

2 files changed

+31
-47
lines changed

2 files changed

+31
-47
lines changed

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

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

3232
package org.scijava.io;
3333

34-
import java.io.IOException;
35-
3634
import org.scijava.plugin.AbstractHandlerPlugin;
3735

3836
/**
@@ -43,44 +41,5 @@
4341
public abstract class AbstractIOPlugin<D> extends AbstractHandlerPlugin<String>
4442
implements IOPlugin<D>
4543
{
46-
47-
// -- IOPlugin methods --
48-
49-
@Override
50-
public boolean supportsOpen(final String source) {
51-
return false;
52-
}
53-
54-
@Override
55-
public boolean supportsSave(final String destination) {
56-
return false;
57-
}
58-
59-
@Override
60-
public boolean supportsSave(final Object data, final String destination) {
61-
return supportsSave(destination) && getDataType().isInstance(data);
62-
}
63-
64-
@Override
65-
public D open(final String source) throws IOException {
66-
throw new UnsupportedOperationException();
67-
}
68-
69-
@Override
70-
public void save(final D data, final String destination) throws IOException {
71-
throw new UnsupportedOperationException();
72-
}
73-
74-
// -- Typed methods --
75-
76-
@Override
77-
public boolean supports(final String descriptor) {
78-
return supportsOpen(descriptor) || supportsSave(descriptor);
79-
}
80-
81-
@Override
82-
public Class<String> getType() {
83-
return String.class;
84-
}
85-
44+
// NB: No implementation needed.
8645
}

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,46 @@ public interface IOPlugin<D> extends HandlerPlugin<String> {
5656
Class<D> getDataType();
5757

5858
/** Checks whether the I/O plugin can open data from the given source. */
59-
boolean supportsOpen(String source);
59+
@SuppressWarnings("unused")
60+
default boolean supportsOpen(final String source) {
61+
return false;
62+
}
6063

6164
/** Checks whether the I/O plugin can save data to the given destination. */
62-
boolean supportsSave(String destination);
65+
@SuppressWarnings("unused")
66+
default boolean supportsSave(final String destination) {
67+
return false;
68+
}
6369

6470
/**
6571
* Checks whether the I/O plugin can save the given data to the specified
6672
* destination.
6773
*/
68-
boolean supportsSave(Object data, String destination);
74+
default boolean supportsSave(final Object data, final String destination) {
75+
return supportsSave(destination) && getDataType().isInstance(data);
76+
}
6977

7078
/** Opens data from the given source. */
71-
D open(String source) throws IOException;
79+
@SuppressWarnings("unused")
80+
default D open(final String source) throws IOException {
81+
throw new UnsupportedOperationException();
82+
}
7283

7384
/** Saves the given data to the specified destination. */
74-
void save(D data, String destination) throws IOException;
85+
@SuppressWarnings("unused")
86+
default void save(final D data, final String destination) throws IOException {
87+
throw new UnsupportedOperationException();
88+
}
7589

90+
// -- Typed methods --
91+
92+
@Override
93+
default boolean supports(final String descriptor) {
94+
return supportsOpen(descriptor) || supportsSave(descriptor);
95+
}
96+
97+
@Override
98+
default Class<String> getType() {
99+
return String.class;
100+
}
76101
}

0 commit comments

Comments
 (0)