Major and minor versions make sense for the current platform only.
@@ -170,11 +170,27 @@ public boolean is(Platform compareWith) {
};
private final String[] partOfOsName;
- private final int minorVersion;
- private final int majorVersion;
+ private int minorVersion = 0;
+ private int majorVersion = 0;
private Platform(String... partOfOsName) {
this.partOfOsName = partOfOsName;
+ }
+
+ public String[] getPartOfOsName() {
+ return partOfOsName;
+ }
+
+ private static Platform current;
+
+ /**
+ * Get current platform (not necessarily the same as operating system).
+ *
+ * @return current platform
+ */
+ public static Platform getCurrent() {
+ if (current == null) {
+ current = extractFromSysProperty(System.getProperty("os.name"));
String version = System.getProperty("os.version", "0.0.0");
int major = 0;
@@ -191,21 +207,10 @@ private Platform(String... partOfOsName) {
}
}
- majorVersion = major;
- minorVersion = min;
- }
-
- public String[] getPartOfOsName() {
- return partOfOsName;
+ current.majorVersion = major;
+ current.minorVersion = min;
}
-
- /**
- * Get current platform (not necessarily the same as operating system).
- *
- * @return current platform
- */
- public static Platform getCurrent() {
- return extractFromSysProperty(System.getProperty("os.name"));
+ return current;
}
/**
