2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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 java.net.MalformedURLException;
24 import java.util.ArrayList;
25 import java.util.HashSet;
26 import java.util.List;
28 import compbio.metadata.*;
30 public class ParameterUtils
32 public static List<String> writeParameterSet(List<Option> optSet,
35 List<String> pset = new ArrayList<String>();
36 for (Option o : optSet)
38 pset.add(o.toCommand(pseparator));
44 * Converts options supplied via parameters file into {@code Option} objects
45 * (Refactored from compbio.ws.client.Jws2Client)
51 * @return List of Options of type T
55 * @SuppressWarnings(value = { "true" }) public static <T> List<Option<T>>
56 * processParameters(List<String> params, RunnerConfig<T> options, String
59 public static List<Option> processParameters(List<String> params,
60 RunnerConfig options, String pseparator)
62 List<Option> chosenOptions = new ArrayList<Option>();
63 for (String param : params)
66 if (isParameter(param, pseparator))
68 oname = getParamName(param, pseparator);
74 Option o = options.getArgumentByOptionName(oname);
77 System.out.println("WARN ignoring unsuppoted parameter: " + oname);
80 if (o instanceof Parameter)
82 o = copyParameter((Parameter) o);
91 o.setDefaultValue(isParameter(param, pseparator) ? getParamValue(
92 param, pseparator) : param);
93 } catch (WrongParameterException e)
95 System.out.println("Problem setting value for the parameter: "
100 chosenOptions.add(o);
102 return chosenOptions;
105 static String getParamName(String fullName, String pseparator)
107 assert isParameter(fullName, pseparator);
108 return fullName.substring(0, fullName.indexOf(pseparator));
111 static String getParamValue(String fullName, String pseparator)
113 assert isParameter(fullName, pseparator);
114 return fullName.substring(fullName.indexOf(pseparator) + 1);
117 static boolean isParameter(String param, String pseparator)
119 return param.contains(pseparator);
122 public static Option copyOption(Option option)
124 Option copy = new Option(option.getName(), option.getDescription());
125 setOptionFrom(copy, option);
129 public static void setOptionFrom(Option copy, Option option)
131 copy.setName(option.getName());
132 copy.setDescription(option.getDescription());
133 copy.setBasicURL(option.getBasicURL());
134 copy.setFurtherDetails(option.getFurtherDetails());
135 copy.setRequired(option.isRequired());
136 List<String> names = option.getOptionNames();
139 if (names.size() == 1)
141 HashSet<String> st = new HashSet();
142 st.add(names.get(0));
143 copy.setOptionNames(st);
147 copy.addOptionNames(names.toArray(new String[]
153 if (option.getDefaultValue() != null)
155 copy.setDefaultValue(option.getDefaultValue());
157 } catch (Exception ex)
159 ex.printStackTrace();
163 public static ValueConstrain copyValueConstrain(ValueConstrain vc)
167 ValueConstrain copy = new ValueConstrain();
168 if (vc.getMax() != null)
170 copy.setMax(vc.getMax().toString());
172 if (vc.getMin() != null)
174 copy.setMin(vc.getMin().toString());
176 if (vc.getType() != null)
178 copy.setType(vc.getType());
181 } catch (Exception e)
185 "Implementation error: could not copy ValueConstrain!");
189 public static Parameter copyParameter(Parameter parameter)
191 Parameter copy = new Parameter(parameter.getName(),
192 parameter.getDescription());
193 if (parameter.getValidValue() != null)
195 copy.setValidValue(copyValueConstrain(parameter.getValidValue()));
197 List<String> pv = parameter.getPossibleValues();
200 copy.addPossibleValues(pv.toArray(new String[]
203 setOptionFrom(copy, parameter);