2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.jws2;
23 import jalview.util.MessageManager;
25 import java.net.MalformedURLException;
26 import java.util.ArrayList;
27 import java.util.HashSet;
28 import java.util.List;
30 import compbio.metadata.*;
32 public class ParameterUtils
34 public static List<String> writeParameterSet(List<Option> optSet,
37 List<String> pset = new ArrayList<String>();
38 for (Option o : optSet)
40 pset.add(o.toCommand(pseparator));
46 * Converts options supplied via parameters file into {@code Option} objects
47 * (Refactored from compbio.ws.client.Jws2Client)
53 * @return List of Options of type T
57 * @SuppressWarnings(value = { "true" }) public static <T> List<Option<T>>
58 * processParameters(List<String> params, RunnerConfig<T> options, String
61 public static List<Option> processParameters(List<String> params,
62 RunnerConfig options, String pseparator)
64 List<Option> chosenOptions = new ArrayList<Option>();
65 for (String param : params)
68 if (isParameter(param, pseparator))
70 oname = getParamName(param, pseparator);
76 Option o = options.getArgumentByOptionName(oname);
79 System.out.println("WARN ignoring unsuppoted parameter: " + oname);
82 if (o instanceof Parameter)
84 o = copyParameter((Parameter) o);
93 o.setDefaultValue(isParameter(param, pseparator) ? getParamValue(
94 param, pseparator) : param);
95 } catch (WrongParameterException e)
97 System.out.println("Problem setting value for the parameter: "
102 chosenOptions.add(o);
104 return chosenOptions;
107 static String getParamName(String fullName, String pseparator)
109 assert isParameter(fullName, pseparator);
110 return fullName.substring(0, fullName.indexOf(pseparator));
113 static String getParamValue(String fullName, String pseparator)
115 assert isParameter(fullName, pseparator);
116 return fullName.substring(fullName.indexOf(pseparator) + 1);
119 static boolean isParameter(String param, String pseparator)
121 return param.contains(pseparator);
124 public static Option copyOption(Option option)
126 Option copy = new Option(option.getName(), option.getDescription());
127 setOptionFrom(copy, option);
131 public static void setOptionFrom(Option copy, Option option)
133 copy.setName(option.getName());
134 copy.setDescription(option.getDescription());
135 copy.setBasicURL(option.getBasicURL());
136 copy.setFurtherDetails(option.getFurtherDetails());
137 copy.setRequired(option.isRequired());
138 List<String> names = option.getOptionNames();
141 if (names.size() == 1)
143 HashSet<String> st = new HashSet();
144 st.add(names.get(0));
145 copy.setOptionNames(st);
149 copy.addOptionNames(names.toArray(new String[]
155 if (option.getDefaultValue() != null)
157 copy.setDefaultValue(option.getDefaultValue());
159 } catch (Exception ex)
161 ex.printStackTrace();
165 public static ValueConstrain copyValueConstrain(ValueConstrain vc)
169 ValueConstrain copy = new ValueConstrain();
170 if (vc.getMax() != null)
172 copy.setMax(vc.getMax().toString());
174 if (vc.getMin() != null)
176 copy.setMin(vc.getMin().toString());
178 if (vc.getType() != null)
180 copy.setType(vc.getType());
183 } catch (Exception e)
186 throw new Error(MessageManager.getString("error.implementation_error_couldnt_copy_value_constraint"));
190 public static Parameter copyParameter(Parameter parameter)
192 Parameter copy = new Parameter(parameter.getName(),
193 parameter.getDescription());
194 if (parameter.getValidValue() != null)
196 copy.setValidValue(copyValueConstrain(parameter.getValidValue()));
198 List<String> pv = parameter.getPossibleValues();
201 copy.addPossibleValues(pv.toArray(new String[]
204 setOptionFrom(copy, parameter);