Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.ws.jws2

File ParameterUtils.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

28
64
9
1
211
162
26
0.41
7.11
9
2.89

Classes

Class Line # Actions
ParameterUtils 35 64 26 101
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.ws.jws2;
22   
23    import jalview.util.MessageManager;
24   
25    import java.util.ArrayList;
26    import java.util.HashSet;
27    import java.util.List;
28   
29    import compbio.metadata.Option;
30    import compbio.metadata.Parameter;
31    import compbio.metadata.RunnerConfig;
32    import compbio.metadata.ValueConstrain;
33    import compbio.metadata.WrongParameterException;
34   
 
35    public class ParameterUtils
36    {
 
37  0 toggle public static List<String> writeParameterSet(List<Option> optSet,
38    String pseparator)
39    {
40  0 List<String> pset = new ArrayList<String>();
41  0 for (Option o : optSet)
42    {
43  0 pset.add(o.toCommand(pseparator));
44    }
45  0 return pset;
46    }
47   
48    /**
49    * Converts options supplied via parameters file into {@code Option} objects
50    * (Refactored from compbio.ws.client.Jws2Client)
51    *
52    * @param <T>
53    * web service type
54    * @param params
55    * @param options
56    * @return List of Options of type T
57    *
58    */
59    /*
60    * @SuppressWarnings(value = { "true" }) public static <T> List<Option<T>>
61    * processParameters(List<String> params, RunnerConfig<T> options, String
62    * pseparator)
63    */
 
64  0 toggle public static List<Option> processParameters(List<String> params,
65    RunnerConfig options, String pseparator)
66    {
67  0 List<Option> chosenOptions = new ArrayList<Option>();
68  0 for (String param : params)
69    {
70  0 String oname = null;
71  0 if (isParameter(param, pseparator))
72    {
73  0 oname = getParamName(param, pseparator);
74    }
75    else
76    {
77  0 oname = param;
78    }
79  0 Option o = options.getArgumentByOptionName(oname);
80  0 if (o == null)
81    {
82  0 System.out.println("WARN ignoring unsuppoted parameter: " + oname);
83  0 continue;
84    }
85  0 if (o instanceof Parameter)
86    {
87  0 o = copyParameter((Parameter) o);
88    }
89    else
90    {
91  0 o = copyOption(o);
92    }
93    {
94  0 try
95    {
96  0 o.setDefaultValue(isParameter(param, pseparator)
97    ? getParamValue(param, pseparator)
98    : param);
99    } catch (WrongParameterException e)
100    {
101  0 System.out.println(
102    "Problem setting value for the parameter: " + param);
103  0 e.printStackTrace();
104    }
105    }
106  0 chosenOptions.add(o);
107    }
108  0 return chosenOptions;
109    }
110   
 
111  0 toggle static String getParamName(String fullName, String pseparator)
112    {
113  0 assert isParameter(fullName, pseparator);
114  0 return fullName.substring(0, fullName.indexOf(pseparator));
115    }
116   
 
117  0 toggle static String getParamValue(String fullName, String pseparator)
118    {
119  0 assert isParameter(fullName, pseparator);
120  0 return fullName.substring(fullName.indexOf(pseparator) + 1);
121    }
122   
 
123  0 toggle static boolean isParameter(String param, String pseparator)
124    {
125  0 return param.contains(pseparator);
126    }
127   
 
128  0 toggle public static Option copyOption(Option option)
129    {
130  0 Option copy = new Option(option.getName(), option.getDescription());
131  0 setOptionFrom(copy, option);
132  0 return copy;
133    }
134   
 
135  0 toggle public static void setOptionFrom(Option copy, Option option)
136    {
137  0 copy.setName(option.getName());
138  0 copy.setDescription(option.getDescription());
139  0 copy.setBasicURL(option.getBasicURL());
140  0 copy.setFurtherDetails(option.getFurtherDetails());
141  0 copy.setRequired(option.isRequired());
142  0 List<String> names = option.getOptionNames();
143  0 if (names != null)
144    {
145  0 if (names.size() == 1)
146    {
147  0 HashSet<String> st = new HashSet();
148  0 st.add(names.get(0));
149  0 copy.setOptionNames(st);
150    }
151    else
152    {
153  0 copy.addOptionNames(names.toArray(new String[] {}));
154    }
155    }
156  0 try
157    {
158  0 if (option.getDefaultValue() != null)
159    {
160  0 copy.setDefaultValue(option.getDefaultValue());
161    }
162    } catch (Exception ex)
163    {
164  0 ex.printStackTrace();
165    }
166    }
167   
 
168  0 toggle public static ValueConstrain copyValueConstrain(ValueConstrain vc)
169    {
170  0 try
171    {
172  0 ValueConstrain copy = new ValueConstrain();
173  0 if (vc.getMax() != null)
174    {
175  0 copy.setMax(vc.getMax().toString());
176    }
177  0 if (vc.getMin() != null)
178    {
179  0 copy.setMin(vc.getMin().toString());
180    }
181  0 if (vc.getType() != null)
182    {
183  0 copy.setType(vc.getType());
184    }
185  0 return copy;
186    } catch (Exception e)
187    {
188  0 e.printStackTrace();
189  0 throw new Error(MessageManager.getString(
190    "error.implementation_error_couldnt_copy_value_constraint"));
191    }
192    }
193   
 
194  0 toggle public static Parameter copyParameter(Parameter parameter)
195    {
196  0 Parameter copy = new Parameter(parameter.getName(),
197    parameter.getDescription());
198  0 if (parameter.getValidValue() != null)
199    {
200  0 copy.setValidValue(copyValueConstrain(parameter.getValidValue()));
201    }
202  0 List<String> pv = parameter.getPossibleValues();
203  0 if (pv != null)
204    {
205  0 copy.addPossibleValues(pv.toArray(new String[] {}));
206    }
207  0 setOptionFrom(copy, parameter);
208  0 return copy;
209    }
210   
211    }