Java Mac OS Version isMacOSVersionLessThan(int major, int minor, int sub)

Here you can find the source of isMacOSVersionLessThan(int major, int minor, int sub)

Description

is Mac OS Version Less Than

License

Open Source License

Parameter

Parameter Description
major Major version (eg 10)
minor Minor version (eg 5)
sub Sub-version (eg 0)

Return

True if user is on Mac and the OS X version is not at least major.minor.sub

Declaration

public static boolean isMacOSVersionLessThan(int major, int minor, int sub) 

Method Source Code

//package com.java2s;
/*/*from w w  w.ja  va  2 s.  com*/
This file is part of leafdigital util.
    
util is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
util is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with util.  If not, see <http://www.gnu.org/licenses/>.
    
Copyright 2011 Samuel Marshall.
*/

import java.util.regex.*;

public class Main {
    private final static Pattern MACOSVERSION = Pattern.compile("^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$");

    /**
     * @param major Major version (eg 10)
     * @param minor Minor version (eg 5)
     * @param sub Sub-version (eg 0)
     * @return True if user is on Mac and the OS X version is not at least major.minor.sub
     */
    public static boolean isMacOSVersionLessThan(int major, int minor, int sub) {
        if (!isMac())
            return false;
        return !isMacOSVersion(major, minor, sub);
    }

    /** @return True if user is on Mac */
    public static boolean isMac() {
        // Code from http://developer.apple.com/technotes/tn2002/tn2110.html
        String lcOSName = System.getProperty("os.name").toLowerCase();
        return lcOSName.startsWith("mac os x");
    }

    /**
     * @param major Major version (eg 10)
     * @param minor Minor version (eg 5)
     * @param sub Sub-version (eg 0)
     * @return True if user is on Mac and the OS X version is at least major.minor.sub
     */
    public static boolean isMacOSVersion(int major, int minor, int sub) {
        if (!isMac())
            return false;
        Matcher m = MACOSVERSION.matcher(System.getProperty("os.version"));
        if (!m.matches())
            return false;
        int actualMajor = Integer.parseInt(m.group(1)), actualMinor = Integer.parseInt(m.group(2)),
                actualSub = Integer.parseInt(m.group(3));
        return actualMajor > major
                || (actualMajor == major && (actualMinor > minor || (actualMinor == minor && actualSub >= sub)));
    }
}

Related

  1. isMacOSVersion(int major, int minor, int sub)