2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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.io.BufferedReader;
21 import java.io.IOException;
22 import java.io.Reader;
23 import java.util.ArrayList;
24 import java.util.HashSet;
25 import java.util.List;
27 import compbio.metadata.*;
29 public class ParameterUtils
31 public static List<String> writeParameterSet(List<Option> optSet, String pseparator)
33 List<String> pset = new ArrayList<String>();
36 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
51 /* @SuppressWarnings(value =
53 public static <T> List<Option<T>> processParameters(List<String> params,
54 RunnerConfig<T> options, String pseparator)
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(param, pseparator) : param);
89 } catch (WrongParameterException e)
91 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.setFurtherDetails(option.getFurtherDetails());
131 copy.setRequired(option.isRequired());
132 List<String> names = option.getOptionNames();
135 if (names.size() == 1)
137 HashSet<String> st = new HashSet();
138 st.add(names.get(0));
139 copy.setOptionNames(st);
143 copy.addOptionNames(names.toArray(new String[]
149 if (option.getDefaultValue() != null)
151 copy.setDefaultValue(option.getDefaultValue());
153 } catch (Exception ex)
155 ex.printStackTrace();
159 public static ValueConstrain copyValueConstrain(ValueConstrain vc)
163 ValueConstrain copy = new ValueConstrain();
164 if (vc.getMax() != null)
166 copy.setMax(vc.getMax().toString());
168 if (vc.getMin() != null)
170 copy.setMin(vc.getMin().toString());
172 if (vc.getType() != null)
174 copy.setType(vc.getType());
177 } catch (Exception e)
181 "Implementation error: could not copy ValueConstrain!");
185 public static Parameter copyParameter(Parameter parameter)
187 Parameter copy = new Parameter(parameter.getName(),
188 parameter.getDescription());
189 if (parameter.getValidValue() != null)
191 copy.setValidValue(copyValueConstrain(parameter.getValidValue()));
193 List<String> pv = parameter.getPossibleValues();
196 copy.addPossibleValues(pv.toArray(new String[]
199 setOptionFrom(copy, parameter);