Skip to content

Commit 010013e

Browse files
committed
Platform: push default method impls to iface
1 parent 07e61f0 commit 010013e

File tree

2 files changed

+46
-76
lines changed

2 files changed

+46
-76
lines changed

src/main/java/org/scijava/platform/AbstractPlatform.java

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -42,82 +42,14 @@ public abstract class AbstractPlatform implements Platform {
4242

4343
// -- Platform methods --
4444

45-
@Override
46-
public String javaVendor() {
47-
return null;
48-
}
49-
50-
@Override
51-
public String javaVersion() {
52-
return null;
53-
}
54-
55-
@Override
56-
public String osArch() {
57-
return null;
58-
}
59-
60-
@Override
61-
public String osName() {
62-
return null;
63-
}
64-
65-
@Override
66-
public String osVersion() {
67-
return null;
68-
}
69-
70-
@Override
71-
public boolean isTarget() {
72-
if (javaVendor() != null) {
73-
final String javaVendor = System.getProperty("java.vendor");
74-
if (!javaVendor.matches(".*" + javaVendor() + ".*")) return false;
75-
}
76-
77-
if (javaVersion() != null) {
78-
final String javaVersion = System.getProperty("java.version");
79-
if (javaVersion.compareTo(javaVersion()) < 0) return false;
80-
}
81-
82-
if (osName() != null) {
83-
final String osName = System.getProperty("os.name");
84-
if (!osName.matches(".*" + osName() + ".*")) return false;
85-
}
86-
87-
if (osArch() != null) {
88-
final String osArch = System.getProperty("os.arch");
89-
if (!osArch.matches(".*" + osArch() + ".*")) return false;
90-
}
91-
92-
if (osVersion() != null) {
93-
final String osVersion = System.getProperty("os.version");
94-
if (osVersion.compareTo(osVersion()) < 0) return false;
95-
}
96-
97-
return true;
98-
}
99-
10045
@Override
10146
public void configure(final PlatformService service) {
10247
platformService = service;
10348
}
10449

105-
@Override
106-
public boolean registerAppMenus(final Object menus) {
107-
return false;
108-
}
109-
110-
// -- Disposable methods --
111-
112-
@Override
113-
public void dispose() {
114-
// NB: Do nothing by default.
115-
}
116-
11750
// -- Internal methods --
11851

11952
protected PlatformService getPlatformService() {
12053
return platformService;
12154
}
122-
12355
}

src/main/java/org/scijava/platform/Platform.java

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,59 @@
5656
public interface Platform extends SingletonPlugin, Disposable {
5757

5858
/** Java Runtime Environment vendor to match. */
59-
String javaVendor();
59+
default String javaVendor() {
60+
return null;
61+
}
6062

6163
/** Minimum required Java Runtime Environment version. */
62-
String javaVersion();
64+
default String javaVersion() {
65+
return null;
66+
}
6367

6468
/** Operating system architecture to match. */
65-
String osArch();
69+
default String osArch() {
70+
return null;
71+
}
6672

6773
/** Operating system name to match. */
68-
String osName();
74+
default String osName() {
75+
return null;
76+
}
6977

7078
/** Minimum required operating system version. */
71-
String osVersion();
79+
default String osVersion() {
80+
return null;
81+
}
7282

7383
/** Determines whether the given platform is applicable to this runtime. */
74-
boolean isTarget();
84+
default boolean isTarget() {
85+
if (javaVendor() != null) {
86+
final String javaVendor = System.getProperty("java.vendor");
87+
if (!javaVendor.matches(".*" + javaVendor() + ".*")) return false;
88+
}
89+
90+
if (javaVersion() != null) {
91+
final String javaVersion = System.getProperty("java.version");
92+
if (javaVersion.compareTo(javaVersion()) < 0) return false;
93+
}
94+
95+
if (osName() != null) {
96+
final String osName = System.getProperty("os.name");
97+
if (!osName.matches(".*" + osName() + ".*")) return false;
98+
}
99+
100+
if (osArch() != null) {
101+
final String osArch = System.getProperty("os.arch");
102+
if (!osArch.matches(".*" + osArch() + ".*")) return false;
103+
}
104+
105+
if (osVersion() != null) {
106+
final String osVersion = System.getProperty("os.version");
107+
if (osVersion.compareTo(osVersion()) < 0) return false;
108+
}
109+
110+
return true;
111+
}
75112

76113
/** Activates and configures the platform. */
77114
void configure(PlatformService service);
@@ -86,6 +123,7 @@ public interface Platform extends SingletonPlugin, Disposable {
86123
* @return true iff the menus should not be added to the UI as normal because
87124
* the platform did something platform-specific with them instead.
88125
*/
89-
boolean registerAppMenus(Object menus);
90-
126+
default boolean registerAppMenus(final Object menus) {
127+
return false;
128+
}
91129
}

0 commit comments

Comments
 (0)