2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.ws.jws2;
20 import java.net.MalformedURLException;
21 import java.util.ArrayList;
22 import java.util.HashSet;
23 import java.util.List;
25 import compbio.metadata.*;
27 public class ParameterUtils
29 public static List<String> writeParameterSet(List<Option> optSet,
32 List<String> pset = new ArrayList<String>();
33 for (Option o : optSet)
35 pset.add(o.toCommand(pseparator));
41 * Converts options supplied via parameters file into {@code Option} objects
42 * (Refactored from compbio.ws.client.Jws2Client)
48 * @return List of Options of type T
52 * @SuppressWarnings(value = { "true" }) public static <T> List<Option<T>>
53 * processParameters(List<String> params, RunnerConfig<T> options, String
56 public static List<Option> processParameters(List<String> params,
57 RunnerConfig options, String pseparator)
59 List<Option> chosenOptions = new ArrayList<Option>();
60 for (String param : params)
63 if (isParameter(param, pseparator))
65 oname = getParamName(param, pseparator);
71 Option o = options.getArgumentByOptionName(oname);
74 System.out.println("WARN ignoring unsuppoted parameter: " + oname);
77 if (o instanceof Parameter)
79 o = copyParameter((Parameter) o);
88 o.setDefaultValue(isParameter(param, pseparator) ? getParamValue(
89 param, pseparator) : param);
90 } catch (WrongParameterException e)
92 System.out.println("Problem setting value for the parameter: "
102 static String getParamName(String fullName, String pseparator)
104 assert isParameter(fullName, pseparator);
105 return fullName.substring(0, fullName.indexOf(pseparator));
108 static String getParamValue(String fullName, String pseparator)
110 assert isParameter(fullName, pseparator);
111 return fullName.substring(fullName.indexOf(pseparator) + 1);
114 static boolean isParameter(String param, String pseparator)
116 return param.contains(pseparator);
119 public static Option copyOption(Option option)
121 Option copy = new Option(option.getName(), option.getDescription());
122 setOptionFrom(copy, option);
126 public static void setOptionFrom(Option copy, Option option)
128 copy.setName(option.getName());
129 copy.setDescription(option.getDescription());
130 copy.setBasicURL(option.getBasicURL());
131 copy.setFurtherDetails(option.getFurtherDetails());
132 copy.setRequired(option.isRequired());
133 List<String> names = option.getOptionNames();
136 if (names.size() == 1)
138 HashSet<String> st = new HashSet();
139 st.add(names.get(0));
140 copy.setOptionNames(st);
144 copy.addOptionNames(names.toArray(new String[]
150 if (option.getDefaultValue() != null)
152 copy.setDefaultValue(option.getDefaultValue());
154 } catch (Exception ex)
156 ex.printStackTrace();
160 public static ValueConstrain copyValueConstrain(ValueConstrain vc)
164 ValueConstrain copy = new ValueConstrain();
165 if (vc.getMax() != null)
167 copy.setMax(vc.getMax().toString());
169 if (vc.getMin() != null)
171 copy.setMin(vc.getMin().toString());
173 if (vc.getType() != null)
175 copy.setType(vc.getType());
178 } catch (Exception e)
182 "Implementation error: could not copy ValueConstrain!");
186 public static Parameter copyParameter(Parameter parameter)
188 Parameter copy = new Parameter(parameter.getName(),
189 parameter.getDescription());
190 if (parameter.getValidValue() != null)
192 copy.setValidValue(copyValueConstrain(parameter.getValidValue()));
194 List<String> pv = parameter.getPossibleValues();
197 copy.addPossibleValues(pv.toArray(new String[]
200 setOptionFrom(copy, parameter);