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.util.ArrayList;
21 import java.util.HashSet;
22 import java.util.List;
24 import compbio.metadata.*;
26 public class ParameterUtils
28 public static List<String> writeParameterSet(List<Option> optSet,
31 List<String> pset = new ArrayList<String>();
32 for (Option o : optSet)
34 pset.add(o.toCommand(pseparator));
40 * Converts options supplied via parameters file into {@code Option} objects
41 * (Refactored from compbio.ws.client.Jws2Client)
47 * @return List of Options of type T
51 * @SuppressWarnings(value = { "true" }) public static <T> List<Option<T>>
52 * processParameters(List<String> params, RunnerConfig<T> options, String
55 public static List<Option> processParameters(List<String> params,
56 RunnerConfig options, String pseparator)
58 List<Option> chosenOptions = new ArrayList<Option>();
59 for (String param : params)
62 if (isParameter(param, pseparator))
64 oname = getParamName(param, pseparator);
70 Option o = options.getArgumentByOptionName(oname);
73 System.out.println("WARN ignoring unsuppoted parameter: " + oname);
76 if (o instanceof Parameter)
78 o = copyParameter((Parameter) o);
87 o.setDefaultValue(isParameter(param, pseparator) ? getParamValue(
88 param, pseparator) : param);
89 } catch (WrongParameterException e)
91 System.out.println("Problem setting value for the parameter: "
101 static String getParamName(String fullName, String pseparator)
103 assert isParameter(fullName, pseparator);
104 return fullName.substring(0, fullName.indexOf(pseparator));
107 static String getParamValue(String fullName, String pseparator)
109 assert isParameter(fullName, pseparator);
110 return fullName.substring(fullName.indexOf(pseparator) + 1);
113 static boolean isParameter(String param, String pseparator)
115 return param.contains(pseparator);
118 public static Option copyOption(Option option)
120 Option copy = new Option(option.getName(), option.getDescription());
121 setOptionFrom(copy, option);
125 public static void setOptionFrom(Option copy, Option option)
127 copy.setName(option.getName());
128 copy.setDescription(option.getDescription());
129 copy.setFurtherDetails(option.getFurtherDetails());
130 copy.setRequired(option.isRequired());
131 List<String> names = option.getOptionNames();
134 if (names.size() == 1)
136 HashSet<String> st = new HashSet();
137 st.add(names.get(0));
138 copy.setOptionNames(st);
142 copy.addOptionNames(names.toArray(new String[]
148 if (option.getDefaultValue() != null)
150 copy.setDefaultValue(option.getDefaultValue());
152 } catch (Exception ex)
154 ex.printStackTrace();
158 public static ValueConstrain copyValueConstrain(ValueConstrain vc)
162 ValueConstrain copy = new ValueConstrain();
163 if (vc.getMax() != null)
165 copy.setMax(vc.getMax().toString());
167 if (vc.getMin() != null)
169 copy.setMin(vc.getMin().toString());
171 if (vc.getType() != null)
173 copy.setType(vc.getType());
176 } catch (Exception e)
180 "Implementation error: could not copy ValueConstrain!");
184 public static Parameter copyParameter(Parameter parameter)
186 Parameter copy = new Parameter(parameter.getName(),
187 parameter.getDescription());
188 if (parameter.getValidValue() != null)
190 copy.setValidValue(copyValueConstrain(parameter.getValidValue()));
192 List<String> pv = parameter.getPossibleValues();
195 copy.addPossibleValues(pv.toArray(new String[]
198 setOptionFrom(copy, parameter);