package com.jasamedika.medifirst2000.util;

/*
 *  Copyright 2011
 *
 *  This file is part of the jLaundry package.
 *
 *  JirehSoft proprietary/confidential. Use is subject to license terms.
 *
 *  Redistribution of this file or of an unauthorized byte-code version
 *  of this file is strictly forbidden
 *
 *  Copyright (c) 2011 by JirehSoft, Jl. Mengger Girang VI No.2A,
 *  Bandung 40254, Indonesia. All rights reserved.
 */


/**
 * <code>JirehSoft</code> class provides common facilities.
 *
 * @author Hutagalung
 */
public class SystemUtil {
    
    private static final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
    private static final boolean isOS2 = System.getProperty("os.name").toLowerCase().contains("os/2");
    private static final boolean isMac = System.getProperty("os.name").toLowerCase().contains("mac");
    private static final boolean isLinux = System.getProperty("os.name").toLowerCase().contains("linux");
    private static final boolean isSunOs = System.getProperty("os.name").toLowerCase().contains("sunos");
    private static final boolean isAIX = System.getProperty("os.name").toLowerCase().contains("aix");
    private static final boolean isHPUX = System.getProperty("os.name").toLowerCase().contains("hpux");
    private static final boolean isFreeBSD = System.getProperty("os.name").toLowerCase().contains("freebsd");
    
    private static Double javaVersion = null;
    
    public static double getJavaVersion() {
        if (javaVersion == null) {
            try {
                String ver = System.getProperties().getProperty("java.version");
                String version = "";
                boolean firstPoint = true;
                
                for (int i = 0; i < ver.length(); i++) {
                    if (ver.charAt(i) == '.') {
                        if (firstPoint)
                            version += ver.charAt(i);
                        firstPoint = false;
                    } else if (Character.isDigit(ver.charAt(i)))
                        version += ver.charAt(i);
                }
                javaVersion = new Double(version);
            } catch (NumberFormatException e) {
            }
        }
        return javaVersion;
    }

    public static boolean isAIX() {
        return isAIX;
    }

    public static boolean isFreeBSD() {
        return isFreeBSD;
    }

    public static boolean isHPUX() {
        return isHPUX;
    }

    public static boolean isLinux() {
        return isLinux;
    }

    public static boolean isMac() {
        return isMac;
    }

    public static boolean isOS2() {
        return isOS2;
    }

    public static boolean isSunOs() {
        return isSunOs;
    }

    public static boolean isWindows() {
        return isWindows;
    }
    
}

