import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
+import java.util.Objects;
import java.util.Properties;
import javax.swing.SwingUtilities;
}
/**
+ * 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 <T>
+ * type of the value
+ * @param defaultValue
+ * default value used if platform not determined
+ * @return platform dependent value wrapper object
+ */
+ public static <T> PlatformDependentValue<T> forArch(T defaultValue)
+ {
+ return new PlatformDependentValue<T>(defaultValue);
+ }
+
+ /**
+ *
+ * @author mmwarowny
+ *
+ * @param <T>
+ * type of the value
+ */
+ public static class PlatformDependentValue<T>
+ {
+ 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<T> forMac(T value)
+ {
+ Objects.requireNonNull(value);
+ macValue = value;
+ return this;
+ }
+
+ /**
+ * Set the value used on Windows platform.
+ *
+ * @param value
+ * parameter value
+ * @return
+ */
+ public PlatformDependentValue<T> forWin(T value)
+ {
+ Objects.requireNonNull(value);
+ winValue = value;
+ return this;
+ }
+
+ /**
+ * Set the value used on Linux platform.
+ *
+ * @param value
+ * parameter value
+ * @return
+ */
+ public PlatformDependentValue<T> forLinux(T value)
+ {
+ Objects.requireNonNull(value);
+ linuxValue = value;
+ return this;
+ }
+
+ /**
+ * Set the value used on JS platform.
+ *
+ * @param value
+ * parameter value
+ * @return
+ */
+ public PlatformDependentValue<T> 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<T> 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
*/