Skip to content

Commit 1afbf42

Browse files
committed
HandlerService: push default method impls to iface
Some minor tweaking is needed in the TextService, since it overrides interface methods in order to specify different javadoc content.
1 parent 010013e commit 1afbf42

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,5 @@
4141
public abstract class AbstractHandlerService<DT, PT extends HandlerPlugin<DT>>
4242
extends AbstractSingletonService<PT> implements HandlerService<DT, PT>
4343
{
44-
45-
// -- HandlerService methods --
46-
47-
@Override
48-
public PT getHandler(final DT data) {
49-
for (final PT handler : getInstances()) {
50-
if (handler.supports(data)) return handler;
51-
}
52-
return null;
53-
}
54-
55-
// -- Typed methods --
56-
57-
@Override
58-
public boolean supports(final DT data) {
59-
return getHandler(data) != null;
60-
}
61-
44+
// NB: No implementation needed.
6245
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ public interface HandlerService<DT, PT extends HandlerPlugin<DT>> extends
5454
* Gets the most appropriate handler for the given data object, or null if no
5555
* handler supports it.
5656
*/
57-
PT getHandler(DT data);
58-
59-
// NB: Javadoc overrides.
57+
default PT getHandler(final DT data) {
58+
for (final PT handler : getInstances()) {
59+
if (handler.supports(data)) return handler;
60+
}
61+
return null;
62+
}
6063

6164
// -- SingletonService methods --
6265

@@ -71,6 +74,7 @@ public interface HandlerService<DT, PT extends HandlerPlugin<DT>> extends
7174

7275
/** Gets whether the given data object is supported. */
7376
@Override
74-
boolean supports(DT data);
75-
77+
default boolean supports(final DT data) {
78+
return getHandler(data) != null;
79+
}
7680
}

src/main/java/org/scijava/text/TextService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public interface TextService extends HandlerService<File, TextFormat>,
5959

6060
/** Gets the text format which best handles the given file. */
6161
@Override
62-
TextFormat getHandler(File file);
62+
default TextFormat getHandler(File file) {
63+
return HandlerService.super.getHandler(file);
64+
}
6365

6466
// -- SingletonService methods --
6567

@@ -71,6 +73,7 @@ public interface TextService extends HandlerService<File, TextFormat>,
7173

7274
/** Gets whether the given file contains text data in a supported format. */
7375
@Override
74-
boolean supports(File file);
75-
76+
default boolean supports(final File file) {
77+
return HandlerService.super.supports(file);
78+
}
7679
}

0 commit comments

Comments
 (0)