package nu.redpois0n.oslib.macos;

import nu.redpois0n.oslib.VersionCompare;

public enum MacOSVersion implements VersionCompare {

    CHEETAH("Cheetah", "10.0", true),
    PUMA("Puma", "10.1", true),
    JAGUAR("Jaguar", "10.2", true),
    PANTHER("Panther", "10.3", true),
    TIGER("Tiger", "10.4", true),
    LEOPARD("Leopard", "10.5", true),
    SNOW_LEOPARD("Snow Leopard", "10.6", true),
    LION("Lion", "10.7", true),
    MOUNTAIN_LION("Mountain Lion", "10.8", true),
    MAVERICKS("Mavericks", "10.9", true),
    YOSEMITE("Yosemite", "10.10", true),
    EL_CAPITAN("El Capitan", "10.11", true),
    SIERRA("Sierra", "10.12");

    private final String search;
    private final String version;
    private final boolean isX;

    MacOSVersion(String search, String version) {
        this(search, version, false);
    }

    MacOSVersion(String search, String version, boolean isX) {
        this.search = search;
        this.version = version;
        this.isX = isX;
    }

    /**
     * Returns codename, such as Yosemite
     */
    public String getDisplay() {
        return search;
    }

    /**
     * Version of OS X, such as 10.10
     */
    public String getVersion() {
        return version;
    }

    /**
     * Indicates if this is Mac OS X or the newer macOS
     *
     * @return if Mac OS X (<= 10.11)
     */
    public boolean isOSX() {
        return this.isX;
    }

    /**
     * Gets MacOSVersion for this machine
     */
    public static MacOSVersion getFromString() {
        return getFromString(System.getProperty("os.version"));
    }

    /**
     * Gets MacOSVersion from string Will detect "10.11.*" if parameter search is is "10.11"
     */
    public static MacOSVersion getFromString(String search) {
        for (MacOSVersion v : MacOSVersion.values()) {
            if (search.startsWith(v.getVersion()) || v.getDisplay().toLowerCase().contains(search.toLowerCase())) {
                return v;
            }
        }

        return null;
    }

    public static MacOSVersion getExact(String display, String version) {
        for (MacOSVersion v : MacOSVersion.values()) {
            if (v.getDisplay().equals(display) && v.getVersion().equals(version)) {
                return v;
            }
        }

        return null;
    }

    @Override
    public boolean isNewer(Enum<?> e) {
        return e.ordinal() > this.ordinal();
    }

    @Override
    public boolean isOlder(Enum<?> e) {
        return e.ordinal() < this.ordinal();
    }
}

@@ -628,16 +628,100 @@
 %2210.12%22)
+,%0A    HIGH_SIERRA(%22High Sierra%22, %2210.13%22, true),%0A    MOJAVE(%22Mojave%22, %2210.14%22, true)
 ;%0A%0A    p
@@ -1843,166 +1843,1044 @@
     
-for (MacOSVersion v : MacOSVersion.values()) %7B%0A            if (search.startsWith(v.getVersion()) %7C%7C v.getDisplay().toLowerCase().contains(search.toLowerCase()
+// check for one with exact match%0A        MacOSVersion exactRes = getExactFromVersion(search);%0A        if (exactRes != null) %7B%0A            return exactRes;%0A        %7D%0A%0A        for (MacOSVersion v : MacOSVersion.values()) %7B%0A            if (search.startsWith(v.getVersion()) %7C%7C v.getDisplay().toLowerCase().contains(search.toLowerCase())) %7B%0A                return v;%0A            %7D%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A    /**%0A     * Gets MacOSVersion by doing an exact match on major and minor version.%0A     * if parameter search is %2210.14.5%22, look for %2210.14%22, considering MacOS history of version numbers%0A     */%0A    public static MacOSVersion getExactFromVersion(String search) %7B%0A        String%5B%5D versionSplit = search.split(%22%5C%5C.%22);%0A        if (versionSplit.length %3E= 2) %7B%0A            versionSplit = new String%5B%5D%7BversionSplit%5B0%5D, versionSplit%5B1%5D%7D;%0A        %7D%0A        String majorMinorVersion = String.join(%22.%22, versionSplit);%0A        for (MacOSVersion v: MacOSVersion.values()) %7B%0A            if (v.getVersion().equals(majorMinorVersion
 )) %7B

patch for recent versions of macos