Skip to content

Commit 64a2333

Browse files
committed
DragAndDropData: move default method impls to iface
1 parent aa07450 commit 64a2333

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

src/main/java/org/scijava/ui/dnd/AbstractDragAndDropData.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,5 @@
4141
public abstract class AbstractDragAndDropData extends AbstractContextual
4242
implements DragAndDropData
4343
{
44-
45-
@Override
46-
public boolean isSupported(final Class<?> type) {
47-
return getMIMEType(type) != null;
48-
}
49-
50-
@Override
51-
public <T> T getData(final Class<T> type) {
52-
final MIMEType mimeType = getMIMEType(type);
53-
if (mimeType == null) return null;
54-
@SuppressWarnings("unchecked")
55-
final T data = (T) getData(mimeType);
56-
return data;
57-
}
58-
59-
@Override
60-
public MIMEType getMIMEType(final Class<?> type) {
61-
for (final MIMEType mimeType : getMIMETypes()) {
62-
if (mimeType.isCompatible(type)) return mimeType;
63-
}
64-
return null;
65-
}
66-
44+
// NB: No implementation needed.
6745
}

src/main/java/org/scijava/ui/dnd/DragAndDropData.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public interface DragAndDropData {
5252
/**
5353
* Gets whether the data can be provided as an object of the given Java class.
5454
*/
55-
boolean isSupported(Class<?> type);
55+
default boolean isSupported(final Class<?> type) {
56+
return getMIMEType(type) != null;
57+
}
5658

5759
/**
5860
* Gets the data with respect to the given MIME type.
@@ -65,10 +67,21 @@ public interface DragAndDropData {
6567
Object getData(MIMEType mimeType);
6668

6769
/** Gets the data as an object of the given Java class. */
68-
<T> T getData(Class<T> type);
70+
default <T> T getData(final Class<T> type) {
71+
final MIMEType mimeType = getMIMEType(type);
72+
if (mimeType == null) return null;
73+
@SuppressWarnings("unchecked")
74+
final T data = (T) getData(mimeType);
75+
return data;
76+
}
6977

7078
/** Gets the best supported MIME type matching the given Java class. */
71-
MIMEType getMIMEType(Class<?> type);
79+
default MIMEType getMIMEType(final Class<?> type) {
80+
for (final MIMEType mimeType : getMIMETypes()) {
81+
if (mimeType.isCompatible(type)) return mimeType;
82+
}
83+
return null;
84+
}
7285

7386
/** Gets the list of supported MIME types. */
7487
List<MIMEType> getMIMETypes();

0 commit comments

Comments
 (0)