Skip to content

Commit fa07e03

Browse files
committed
Cleaning and optimizing the OS utility class
1 parent d8a819a commit fa07e03

File tree

1 file changed

+14
-12
lines changed
  • src/main/java/com/nativejavafx/taskbar/util

1 file changed

+14
-12
lines changed

src/main/java/com/nativejavafx/taskbar/util/OS.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
* application runs on.
77
*/
88
public class OS {
9+
10+
private static final String OS = System.getProperty("os.name");
11+
private static final String VERSION = System.getProperty("os.version");
12+
13+
private static final boolean WINDOWS = OS.startsWith("Windows");
14+
private static final boolean WINDOWS_7_OR_LATER = WINDOWS && versionGreaterThanOrEqualTo(6.1F);
15+
916
private OS() {
1017
}
1118

@@ -16,19 +23,14 @@ private OS() {
1623
* <code>false</code> otherwise
1724
*/
1825
public static boolean isWindows7OrLater() {
19-
double version = Double.parseDouble(System.getProperty("os.version"));
20-
double win7Version = 6.1; //Windows 7 has this version number
21-
22-
return isWindows() && version >= win7Version;
26+
return WINDOWS_7_OR_LATER;
2327
}
2428

25-
/**
26-
* Checks that the OS is windows or not.
27-
*
28-
* @return <code>true</code> if the OS is windows;
29-
* <code>false</code> otherwise
30-
*/
31-
public static boolean isWindows() {
32-
return System.getProperty("os.name").startsWith("Windows");
29+
public static boolean versionGreaterThanOrEqualTo(float value) {
30+
try {
31+
return Float.parseFloat(VERSION) >= value;
32+
} catch (Exception e) {
33+
return false;
34+
}
3335
}
3436
}

0 commit comments

Comments
 (0)