Skip to content

Commit 5cee4bb

Browse files
committed
Refactor OS class to optimize OS name retrieval
- Introduced a static final variable `OS_NAME` to store the lowercased OS name, reducing repeated calls to `System.getProperty()`. - Updated methods `isWindows()`, `isLinux()`, `getOSName()`, and `isMacOS()` to utilize the new `OS_NAME` variable for improved performance and readability.
1 parent 109af13 commit 5cee4bb

File tree

1 file changed

+5
-4
lines changed
  • src/main/java/de/doubleslash/keeptime/common

1 file changed

+5
-4
lines changed

src/main/java/de/doubleslash/keeptime/common/OS.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,26 @@
1919
public class OS {
2020

2121
private static final String OS_PROPERTY = "os.name";
22+
private static final String OS_NAME = System.getProperty(OS_PROPERTY).toLowerCase();
2223

2324
private OS() {
2425
// prevent instance creation
2526
}
2627

2728
public static boolean isWindows() {
28-
return System.getProperty(OS_PROPERTY).toLowerCase().contains("windows");
29+
return OS_NAME.contains("windows");
2930
}
3031

3132
public static boolean isLinux() {
32-
return System.getProperty(OS_PROPERTY).toLowerCase().contains("linux");
33+
return OS_NAME.contains("linux");
3334
}
3435

3536
public static String getOSName() {
36-
return System.getProperty(OS_PROPERTY);
37+
return OS_NAME;
3738
}
3839

3940
public static boolean isMacOS() {
40-
return getOSName().toLowerCase().contains("mac os x");
41+
return OS_NAME.contains("mac os x");
4142
}
4243

4344
}

0 commit comments

Comments
 (0)