X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FPlatform.java;fp=src%2Fjalview%2Futil%2FPlatform.java;h=11b6270b856c8b4305bf6cc5f40151cae23a5038;hb=bbbb2ef0684fd96fce3c46b78356c47b624e70cc;hp=5b89db31a3788d4aceb5106a0177d40dfb92dfd4;hpb=6c03a34084889aebdb94a8653a9955f8efd0da88;p=jalview.git diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index 5b89db3..11b6270 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -47,6 +47,7 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.Date; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Properties; import java.util.logging.ConsoleHandler; import java.util.logging.Level; @@ -229,6 +230,147 @@ public class Platform } /** + * Construct the value that depends on the system architecture. The methods + * setting the value for subsequent platforms are chained after this call and + * finalized with a {@link PlatformDependentValue#value() value()} call. + * + * Example: {@code + * Platform.forArch(120).forMac(114).forWin(112).forLinux(115).value(); + * } + * + * @param + * type of the value + * @param defaultValue + * default value used if platform not determined + * @return platform dependent value wrapper object + */ + public static PlatformDependentValue forArch(T defaultValue) + { + return new PlatformDependentValue(defaultValue); + } + + /** + * + * @author mmwarowny + * + * @param + * type of the value + */ + public static class PlatformDependentValue + { + private T defaultValue = null; + + private T macValue = null; + + private T winValue = null; + + private T linuxValue = null; + + private T jsValue = null; + + private T headlessValue = null; + + private PlatformDependentValue(T value) + { + Objects.requireNonNull(value); + defaultValue = value; + } + + /** + * Set the value used on Mac platform. + * + * @param value + * parameter value + * @return + */ + public PlatformDependentValue forMac(T value) + { + Objects.requireNonNull(value); + macValue = value; + return this; + } + + /** + * Set the value used on Windows platform. + * + * @param value + * parameter value + * @return + */ + public PlatformDependentValue forWin(T value) + { + Objects.requireNonNull(value); + winValue = value; + return this; + } + + /** + * Set the value used on Linux platform. + * + * @param value + * parameter value + * @return + */ + public PlatformDependentValue forLinux(T value) + { + Objects.requireNonNull(value); + linuxValue = value; + return this; + } + + /** + * Set the value used on JS platform. + * + * @param value + * parameter value + * @return + */ + public PlatformDependentValue forJS(T value) + { + Objects.requireNonNull(value); + jsValue = value; + return this; + } + + /** + * Set the value used on headless platform. The headless value takes + * precedence over other platforms if set. + * + * @param value + * parameter value + * @return + */ + public PlatformDependentValue forHeadless(T value) + { + Objects.requireNonNull(value); + headlessValue = value; + return this; + } + + /** + * Get the value of the parameter respecting the platform. The headless + * platform takes precedence over any other platform if it has the value + * set. + * + * @return parameter value depending on the platform + */ + public T value() + { + if (headlessValue != null && isHeadless()) + return headlessValue; + if (macValue != null && isMac()) + return macValue; + if (winValue != null && isWin()) + return winValue; + if (linuxValue != null && isLinux()) + return linuxValue; + if (jsValue != null && isJS()) + return jsValue; + return defaultValue; + } + } + + /** * * @return nominal maximum command line length for this platform */