Skip to content

Commit 9572dac

Browse files
committed
MutableModule: move default method impls to iface
1 parent 8d1f80b commit 9572dac

File tree

2 files changed

+34
-58
lines changed

2 files changed

+34
-58
lines changed

src/main/java/org/scijava/module/DefaultMutableModule.java

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -52,60 +52,10 @@ public DefaultMutableModule(final MutableModuleInfo info) {
5252
info.setModuleClass(getClass());
5353
}
5454

55-
// -- MutableModule methods --
56-
57-
@Override
58-
public <T> MutableModuleItem<T> addInput(final String name,
59-
final Class<T> type)
60-
{
61-
final DefaultMutableModuleItem<T> item =
62-
new DefaultMutableModuleItem<>(this, name, type);
63-
addInput(item);
64-
return item;
65-
}
66-
67-
@Override
68-
public void addInput(final ModuleItem<?> input) {
69-
getInfo().addInput(input);
70-
}
71-
72-
@Override
73-
public <T> MutableModuleItem<T> addOutput(final String name,
74-
final Class<T> type)
75-
{
76-
final DefaultMutableModuleItem<T> item =
77-
new DefaultMutableModuleItem<>(this, name, type);
78-
addOutput(item);
79-
return item;
80-
}
81-
82-
@Override
83-
public void addOutput(final ModuleItem<?> output) {
84-
getInfo().addOutput(output);
85-
}
86-
87-
@Override
88-
public void removeInput(final ModuleItem<?> input) {
89-
getInfo().removeInput(input);
90-
}
91-
92-
@Override
93-
public void removeOutput(final ModuleItem<?> output) {
94-
getInfo().removeOutput(output);
95-
}
96-
9755
// -- Module methods --
9856

9957
@Override
10058
public MutableModuleInfo getInfo() {
10159
return info;
10260
}
103-
104-
// -- Runnable methods --
105-
106-
@Override
107-
public void run() {
108-
// do nothing by default
109-
}
110-
11161
}

src/main/java/org/scijava/module/MutableModule.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,54 @@
4747
public interface MutableModule extends Module {
4848

4949
/** Adds an input to the list. */
50-
<T> MutableModuleItem<T> addInput(String name, Class<T> type);
50+
default <T> MutableModuleItem<T> addInput(final String name,
51+
final Class<T> type)
52+
{
53+
final DefaultMutableModuleItem<T> item =
54+
new DefaultMutableModuleItem<>(this, name, type);
55+
addInput(item);
56+
return item;
57+
}
5158

5259
/** Adds an input to the list. */
53-
void addInput(ModuleItem<?> input);
60+
default void addInput(final ModuleItem<?> input) {
61+
getInfo().addInput(input);
62+
}
5463

5564
/** Adds an output to the list. */
56-
<T> MutableModuleItem<T> addOutput(String name, Class<T> type);
65+
default <T> MutableModuleItem<T> addOutput(final String name,
66+
final Class<T> type)
67+
{
68+
final DefaultMutableModuleItem<T> item =
69+
new DefaultMutableModuleItem<>(this, name, type);
70+
addOutput(item);
71+
return item;
72+
}
5773

5874
/** Adds an output to the list. */
59-
void addOutput(ModuleItem<?> output);
75+
default void addOutput(final ModuleItem<?> output) {
76+
getInfo().addOutput(output);
77+
}
6078

6179
/** Removes an input from the list. */
62-
void removeInput(ModuleItem<?> input);
80+
default void removeInput(final ModuleItem<?> input) {
81+
getInfo().removeInput(input);
82+
}
6383

6484
/** Removes an output from the list. */
65-
void removeOutput(ModuleItem<?> output);
66-
67-
// NB: Type narrowing.
85+
default void removeOutput(final ModuleItem<?> output) {
86+
getInfo().removeOutput(output);
87+
}
6888

6989
// -- ModuleInfo methods --
7090

7191
@Override
7292
MutableModuleInfo getInfo();
7393

94+
// -- Runnable methods --
95+
96+
@Override
97+
default void run() {
98+
// do nothing by default
99+
}
74100
}

0 commit comments

Comments
 (0)