package com.yfd.platform.utils;


public class OSInfoUtils {

    private static String Any = "any";
    private static String Linux = "Linux";
    private static String Mac_OS = "Mac OS";
    private static String Mac_OS_X = "Mac OS X";
    private static String Windows = "Windows";
    private static String OS2 = "OS/2";
    private static String Solaris = "Solaris";
    private static String SunOS = "SunOS";
    private static String MPEiX = "MPE/iX";
    private static String HP_UX = "HP-UX";
    private static String AIX = "AIX";
    private static String OS390 = "OS/390";
    private static String FreeBSD = "FreeBSD";
    private static String Irix = "Irix";
    private static String Digital_Unix = "Digital Unix";
    private static String NetWare_411 = "NetWare";
    private static String OSF1 = "OSF1";
    private static String OpenVMS = "OpenVMS";
    private static String Others = "Others";

    private static String OS = System.getProperty("os.name").toLowerCase();

    private static OSInfoUtils _instance = new OSInfoUtils();

    private String platform;

    private OSInfoUtils(){}

    public static boolean isLinux(){
        return OS.indexOf("linux")>=0;
    }

    public static boolean isMacOS(){
        return OS.indexOf("mac")>=0&&OS.indexOf("os")>0&&OS.indexOf("x")<0;
    }

    public static boolean isMacOSX(){
        return OS.indexOf("mac")>=0&&OS.indexOf("os")>0&&OS.indexOf("x")>0;
    }

    public static boolean isWindows(){
        return OS.indexOf("windows")>=0;
    }

    public static boolean isOS2(){
        return OS.indexOf("os/2")>=0;
    }

    public static boolean isSolaris(){
        return OS.indexOf("solaris")>=0;
    }

    public static boolean isSunOS(){
        return OS.indexOf("sunos")>=0;
    }

    public static boolean isMPEiX(){
        return OS.indexOf("mpe/ix")>=0;
    }

    public static boolean isHPUX(){
        return OS.indexOf("hp-ux")>=0;
    }

    public static boolean isAix(){
        return OS.indexOf("aix")>=0;
    }

    public static boolean isOS390(){
        return OS.indexOf("os/390")>=0;
    }

    public static boolean isFreeBSD(){
        return OS.indexOf("freebsd")>=0;
    }

    public static boolean isIrix(){
        return OS.indexOf("irix")>=0;
    }

    public static boolean isDigitalUnix(){
        return OS.indexOf("digital")>=0&&OS.indexOf("unix")>0;
    }

    public static boolean isNetWare(){
        return OS.indexOf("netware")>=0;
    }

    public static boolean isOSF1(){
        return OS.indexOf("osf1")>=0;
    }

    public static boolean isOpenVMS(){
        return OS.indexOf("openvms")>=0;
    }

    /**
     * 获取操作系统名字
     * @return 操作系统名
     */
    public static String getOSname(){
        if(isAix()){
            _instance.platform = AIX;
        }else if (isDigitalUnix()) {
            _instance.platform = Digital_Unix;
        }else if (isFreeBSD()) {
            _instance.platform = FreeBSD;
        }else if (isHPUX()) {
            _instance.platform = HP_UX;
        }else if (isIrix()) {
            _instance.platform = Irix;
        }else if (isLinux()) {
            _instance.platform = Linux;
        }else if (isMacOS()) {
            _instance.platform = Mac_OS;
        }else if (isMacOSX()) {
            _instance.platform = Mac_OS_X;
        }else if (isMPEiX()) {
            _instance.platform = MPEiX;
        }else if (isNetWare()) {
            _instance.platform = NetWare_411;
        }else if (isOpenVMS()) {
            _instance.platform = OpenVMS;
        }else if (isOS2()) {
            _instance.platform = OS2;
        }else if (isOS390()) {
            _instance.platform = OS390;
        }else if (isOSF1()) {
            _instance.platform = OSF1;
        }else if (isSolaris()) {
            _instance.platform = Solaris;
        }else if (isSunOS()) {
            _instance.platform = SunOS;
        }else if (isWindows()) {
            _instance.platform = Windows;
        }else{
            _instance.platform = Others;
        }
        return _instance.platform;
    }

}

