CrossPlatformCommand

public abstract class CrossPlatformCommand<T>

A command that when run will execute the proper method for the specified operating system. This is especially useful when you are trying to create for handling different platforms. Here is an example usage of the class:

final Boolean result = new CrossPlatformCommand<Boolean>() {
    &#064;Override protected Boolean onWindows() {
    //do your logic for windows
    }

    &#064;Override protected Boolean onUnix() {
    //do your logic for unix
    }

    &#064;Override protected Boolean onMac() {
    //do your logic for mac
    }

    &#064;Override protected Boolean onSolaris() {
    //do your logic for solaris
    }
}.execute();
Parameters:
  • <T> – the result from the command.

Methods

execute

public T execute()

Main method that should be executed. This will return the proper result depending on your platform.

Returns:the result

isMac

public static boolean isMac()

Check if the current OS is MacOS.

Returns:true if macOS and false otherwise

isSolaris

public static boolean isSolaris()

Check if the current OS is Solaris.

Returns:true if solaris and false otherwise

isUnix

public static boolean isUnix()

Check if the current OS is some sort of unix.

Returns:true if unix and false otherwise

isWindows

public static boolean isWindows()

Check if the current OS is windows.

Returns:true if windows and false otherwise

onMac

protected T onMac()

What to execute on macOS.

Returns:the result

onSolaris

protected T onSolaris()

What to execute on solaris.

Returns:the result

onUnix

protected abstract T onUnix()

What to execute on windows.

Returns:the result

onWindows

protected abstract T onWindows()

What to execute on windows.

Returns:the result

setOS

static void setOS(String newOs)