package org.unix4j.util;

/**
 * Enum constants for operating systems.
 */
public enum OS {
	/** Windows, any version */
	Windows {
		@Override
		public boolean isCurrent(String osName) {
			return osName.indexOf("win") >= 0;
		}
	},
	/** MAC */
	Mac {
		@Override
		public boolean isCurrent(String osName) {
			return osName.indexOf("mac") >= 0;
		}
	},
	/** Linux or other Unix */
	Unix {
		@Override
		public boolean isCurrent(String osName) {
			return osName.indexOf("nix") >= 0 || osName.indexOf("nux") >= 0;
		}
	},
	/** SUN Solaris */
	Solaris {
		@Override
		public boolean isCurrent(String osName) {
			return osName.indexOf("sunos") >= 0;
		}
	};
	
	public boolean isCurrent() {
		return isCurrent(System.getProperty("os.name").toLowerCase());
	}

	abstract protected boolean isCurrent(String osName);
	
	public static OS current() {
		for (final OS os : values()) {
			if (os.isCurrent()) return os;
		}
		throw new IllegalStateException("Cannot evaluate OS constant for current operating system: " + System.getProperty("os.name"));
	}
}
@@ -21,16 +21,107 @@
 til;%0D%0A%0D%0A
+import java.util.function.Predicate;%0D%0A%0D%0Aimport static java.util.Objects.requireNonNull;%0D%0A%0D%0A
 /**%0D%0A * 
@@ -224,244 +224,96 @@
 dows
- %7B%0D%0A%09%09@Override%0D%0A%09%09public boolean isCurrent(String osName) %7B%0D%0A%09%09%09return osName.indexOf(%22win%22) %3E= 0;%0D%0A%09%09%7D%0D%0A%09%7D,%0D%0A%09/** MAC */%0D%0A%09Mac %7B%0D%0A%09%09@Override%0D%0A%09%09public boolean isCurrent(String osName) %7B%0D%0A%09%09%09return osName.indexOf(%22mac%22) %3E= 0;%0D%0A%09%09%7D%0D%0A%09%7D
+(osName -%3E osName.contains(%22win%22)),%0D%0A%09/** MAC */%0D%0A%09Mac(osName -%3E osName.contains(%22mac%22))
 ,%0D%0A%09
@@ -321,16 +321,21 @@
 ** Linux
+, AIX
  or othe
@@ -354,106 +354,41 @@
 Unix
- %7B%0D%0A%09%09@Override%0D%0A%09%09public boolean isCurrent(String osName) %7B%0D%0A%09%09%09return osName.indexOf
+(osName -%3E osName.contains
 (%22nix%22)
- %3E= 0
  %7C%7C 
@@ -398,375 +398,636 @@
 ame.
-indexOf(%22nux%22) %3E= 0;%0D%0A%09%09%7D%0D%0A%09%7D,%0D%0A%09/** SUN Solaris */%0D%0A%09Solaris %7B%0D%0A%09%09@Override%0D%0A%09%09public boolean isCurrent(
+contains(%22nux%22) %7C%7C osName.contains(%22aix%22)),%0D%0A%09/** SUN Solaris */%0D%0A%09Solaris(osName -%3E osName.contains(%22sunos%22)),%0D%0A%09/** Any other unrecognised OS */%0D%0A%09Other(osName -%3E true);%0D%0A%0D%0A%09private final Predicate%3C? super String%3E osNameMatcher;%0D%0A%09%0D%0A%09OS(final Predicate%3C? super 
 String
+%3E
  osName
-) %7B%0D%0A%09%09%09return osName.indexOf(%22sunos%22) %3E= 0
+Matcher) %7B%0D%0A%09%09this.osNameMatcher = requireNonNull(osNameMatcher)
 ;%0D%0A
-%09
 %09%7D%0D%0A%09
-%7D;
 %0D%0A%09
-%0D%0A%09public boolean isCurrent() %7B%0D%0A%09%09return isCurrent(System.getProperty(%22os.name%22).toLowerCase());%0D%0A%09%7D%0D%0A%0D%0A%09abstract protected boolean isCurrent(String osName);%0D%0A%09%0D%0A%09public static OS current() %7B
+private static final OS CURRENT = initCurrent();%0D%0A%0D%0A%09public boolean isCurrent() %7B%0D%0A%09%09return this == CURRENT;%0D%0A%09%7D%0D%0A%0D%0A%09public static OS current() %7B%0D%0A%09%09return CURRENT;%0D%0A%09%7D%0D%0A%0D%0A%09private static OS initCurrent() %7B%0D%0A%09%09final String osName = System.getProperty(%22os.name%22).toLowerCase();
 %0D%0A%09%09
@@ -1072,21 +1072,43 @@
 (os.
-isCurrent()) 
+osNameMatcher.test(osName)) %7B%0D%0A%09%09%09%09
 retu
@@ -1119,140 +1119,58 @@
 s;%0D%0A
+%09%09%09%7D%0D%0A
 %09%09%7D%0D%0A%09%09
-throw new IllegalStateException(%22Cannot evaluate OS constant for current operating system: %22 + System.getProperty(%22os.name%22))
+//should not get here%0D%0A%09%09return Other
 ;%0D%0A%09

Fix for issue #75: add 'aix' as unix OS and add Other for unrecognised OS instead of throwing an exception