1 package jalview.ws.jws2;
3 import java.io.BufferedReader;
4 import java.io.IOException;
6 import java.util.ArrayList;
7 import java.util.HashSet;
10 import compbio.metadata.*;
12 public class ParameterUtils
14 public static List<String> writeParameterSet(List<Option> optSet, String pseparator)
16 List<String> pset = new ArrayList<String>();
19 pset.add(o.toCommand(pseparator));
24 * Converts options supplied via parameters file into {@code Option} objects
25 * (Refactored from compbio.ws.client.Jws2Client)
31 * @return List of Options of type T
34 /* @SuppressWarnings(value =
36 public static <T> List<Option<T>> processParameters(List<String> params,
37 RunnerConfig<T> options, String pseparator)
39 public static List<Option> processParameters(List<String> params,
40 RunnerConfig options, String pseparator)
42 List<Option> chosenOptions = new ArrayList<Option>();
43 for (String param : params)
46 if (isParameter(param, pseparator))
48 oname = getParamName(param, pseparator);
54 Option o = options.getArgumentByOptionName(oname);
57 System.out.println("WARN ignoring unsuppoted parameter: " + oname);
60 if (o instanceof Parameter)
62 o = copyParameter((Parameter) o);
71 o.setDefaultValue(isParameter(param, pseparator) ? getParamValue(param, pseparator) : param);
72 } catch (WrongParameterException e)
74 System.out.println("Problem setting value for the parameter: "
85 static String getParamName(String fullName, String pseparator)
87 assert isParameter(fullName, pseparator);
88 return fullName.substring(0, fullName.indexOf(pseparator));
91 static String getParamValue(String fullName, String pseparator)
93 assert isParameter(fullName, pseparator);
94 return fullName.substring(fullName.indexOf(pseparator) + 1);
97 static boolean isParameter(String param, String pseparator)
99 return param.contains(pseparator);
102 public static Option copyOption(Option option)
104 Option copy = new Option(option.getName(), option.getDescription());
105 setOptionFrom(copy, option);
109 public static void setOptionFrom(Option copy, Option option)
111 copy.setName(option.getName());
112 copy.setDescription(option.getDescription());
113 copy.setFurtherDetails(option.getFurtherDetails());
114 copy.setRequired(option.isRequired());
115 List<String> names = option.getOptionNames();
118 if (names.size() == 1)
120 HashSet<String> st = new HashSet();
121 st.add(names.get(0));
122 copy.setOptionNames(st);
126 copy.addOptionNames(names.toArray(new String[]
132 if (option.getDefaultValue() != null)
134 copy.setDefaultValue(option.getDefaultValue());
136 } catch (Exception ex)
138 ex.printStackTrace();
142 public static ValueConstrain copyValueConstrain(ValueConstrain vc)
146 ValueConstrain copy = new ValueConstrain();
147 if (vc.getMax() != null)
149 copy.setMax(vc.getMax().toString());
151 if (vc.getMin() != null)
153 copy.setMin(vc.getMin().toString());
155 if (vc.getType() != null)
157 copy.setType(vc.getType());
160 } catch (Exception e)
164 "Implementation error: could not copy ValueConstrain!");
168 public static Parameter copyParameter(Parameter parameter)
170 Parameter copy = new Parameter(parameter.getName(),
171 parameter.getDescription());
172 if (parameter.getValidValue() != null)
174 copy.setValidValue(copyValueConstrain(parameter.getValidValue()));
176 List<String> pv = parameter.getPossibleValues();
179 copy.addPossibleValues(pv.toArray(new String[]
182 setOptionFrom(copy, parameter);