OSValidator.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.data.util;
00002 
00003 /*******************************************************
00004  * Check the Operating system of the current JVM
00005  * @author laksonoadhianto
00006  *
00007  *******************************************************/
00008 public class OSValidator {
00009     
00010     static private final String os = OSValidator.getOS();
00011     static private final boolean mac = ( os.indexOf("mac") >= 0 );
00012     static private final boolean win = ( os.indexOf("win") >= 0 );
00013     static private final boolean unix = ( os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0 );
00014     
00015     /****
00016      * test unit
00017      * @param args
00018      */
00019     public static void main(String[] args)
00020     {
00021         if(isWindows()){
00022             System.out.println("This is Windows");
00023         }else if(isMac()){
00024             System.out.println("This is Mac");
00025         }else if(isUnix()){
00026             System.out.println("This is Unix or Linux");
00027         }else{
00028             System.out.println("Your OS is not supported!!");
00029         }
00030     }
00031  
00032     /******
00033      * check if we are on windows
00034      * @return true if win* is the current OS
00035      */
00036     public static boolean isWindows(){
00037         return win; 
00038     }
00039  
00040     /******
00041      * check if we are on mac
00042      * @return true if mac* is the current OS
00043      */
00044     public static boolean isMac(){
00045         return mac; 
00046     }
00047  
00048     /******
00049      * check if we are on unix or linux
00050      * @return true if *nix or *nux is the current OS
00051      */
00052     public static boolean isUnix(){ 
00053         return unix;
00054     }
00055 
00056         
00057     private static String getOS() {
00058         return System.getProperty("os.name").toLowerCase();
00059     }
00060 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1