--- /dev/null
+package jalview.ws.jws2;
+
+import java.util.HashSet;
+import java.util.List;
+
+import compbio.metadata.*;
+public class ParameterUtils
+{
+
+ public static Option copyOption(Option option)
+ {
+ Option copy = new Option(option.getName(), option.getDescription());
+ setOptionFrom(copy, option);
+ return copy;
+ }
+ public static void setOptionFrom(Option copy, Option option)
+ {
+ copy.setName(option.getName());
+ copy.setDescription(option.getDescription());
+ copy.setFurtherDetails(option.getFurtherDetails());
+ copy.setRequired(option.isRequired());
+ List<String> names = option.getOptionNames();
+ if (names!=null){
+ if (names.size()==1)
+ {
+ HashSet<String> st = new HashSet();
+ st.add(names.get(0));
+ copy.setOptionNames(st);
+ } else {
+ copy.addOptionNames(names.toArray(new String[]{}));
+ }
+ }
+ try {
+ if (option.getDefaultValue()!=null)
+ {
+ copy.setDefaultValue(option.getDefaultValue());
+ }
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public static ValueConstrain copyValueConstrain(ValueConstrain vc)
+ {
+ try {ValueConstrain copy = new ValueConstrain();
+ if (vc.getMax()!=null) {
+ copy.setMax(vc.getMax().toString());
+ }
+ if (vc.getMin()!=null) {
+ copy.setMin(vc.getMin().toString());
+ }
+ if (vc.getType()!=null) {
+ copy.setType(vc.getType());
+ }
+ return copy;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new Error("Implementation error: could not copy ValueConstrain!");
+ }
+ }
+ public static Parameter copyParameter(Parameter parameter)
+ {
+ Parameter copy = new Parameter(parameter.getName(), parameter.getDescription());
+ if (parameter.getValidValue()!=null) {
+ copy.setValidValue(copyValueConstrain(parameter.getValidValue()));
+ }
+ List<String> pv = parameter.getPossibleValues();
+ if (pv!=null)
+ {
+ copy.addPossibleValues(pv.toArray(new String[]{}));
+ }
+ setOptionFrom(copy, parameter);
+ return copy;
+ }
+
+}