Created
April 10, 2017 09:54
-
-
Save luanvuhlu/2ef09723733595ca2ef1c7c78efe8fe7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class OsCheck { | |
/** | |
* types of Operating Systems | |
*/ | |
public enum OSType { | |
Windows, MacOS, Linux, Other | |
}; | |
// cached result of OS detection | |
protected static OSType detectedOS; | |
private OsCheck(){ | |
} | |
/** | |
* detect the operating system from the os.name System property and cache | |
* the result | |
* | |
* @returns - the operating system detected | |
*/ | |
public static OSType getOperatingSystemType() { | |
if (detectedOS == null) { | |
String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH); | |
if ((OS.indexOf("mac") >= 0) || (OS.indexOf("darwin") >= 0)) { | |
detectedOS = OSType.MacOS; | |
} else if (OS.indexOf("win") >= 0) { | |
detectedOS = OSType.Windows; | |
} else if (OS.indexOf("nux") >= 0) { | |
detectedOS = OSType.Linux; | |
} else { | |
detectedOS = OSType.Other; | |
} | |
} | |
return detectedOS; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment