1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 101 (101) |
Complexity: 26 |
Complexity Density: 0.41 |
|
35 |
|
public class ParameterUtils |
36 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
37 |
0 |
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 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@param |
53 |
|
|
54 |
|
@param |
55 |
|
@param |
56 |
|
@return |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 6 |
Complexity Density: 0.32 |
|
64 |
0 |
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 |
jalview.bin.Console |
83 |
|
.outPrintln("WARN ignoring unsuppoted parameter: " + oname); |
84 |
0 |
continue; |
85 |
|
} |
86 |
0 |
if (o instanceof Parameter) |
87 |
|
{ |
88 |
0 |
o = copyParameter((Parameter) o); |
89 |
|
} |
90 |
|
else |
91 |
|
{ |
92 |
0 |
o = copyOption(o); |
93 |
|
} |
94 |
|
{ |
95 |
0 |
try |
96 |
|
{ |
97 |
0 |
o.setDefaultValue(isParameter(param, pseparator) |
98 |
|
? getParamValue(param, pseparator) |
99 |
|
: param); |
100 |
|
} catch (WrongParameterException e) |
101 |
|
{ |
102 |
0 |
jalview.bin.Console.outPrintln( |
103 |
|
"Problem setting value for the parameter: " + param); |
104 |
0 |
e.printStackTrace(); |
105 |
|
} |
106 |
|
} |
107 |
0 |
chosenOptions.add(o); |
108 |
|
} |
109 |
0 |
return chosenOptions; |
110 |
|
} |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
112 |
0 |
static String getParamName(String fullName, String pseparator)... |
113 |
|
{ |
114 |
0 |
assert isParameter(fullName, pseparator); |
115 |
0 |
return fullName.substring(0, fullName.indexOf(pseparator)); |
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
118 |
0 |
static String getParamValue(String fullName, String pseparator)... |
119 |
|
{ |
120 |
0 |
assert isParameter(fullName, pseparator); |
121 |
0 |
return fullName.substring(fullName.indexOf(pseparator) + 1); |
122 |
|
} |
123 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
0 |
static boolean isParameter(String param, String pseparator)... |
125 |
|
{ |
126 |
0 |
return param.contains(pseparator); |
127 |
|
} |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
129 |
0 |
public static Option copyOption(Option option)... |
130 |
|
{ |
131 |
0 |
Option copy = new Option(option.getName(), option.getDescription()); |
132 |
0 |
setOptionFrom(copy, option); |
133 |
0 |
return copy; |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 5 |
Complexity Density: 0.31 |
|
136 |
0 |
public static void setOptionFrom(Option copy, Option option)... |
137 |
|
{ |
138 |
0 |
copy.setName(option.getName()); |
139 |
0 |
copy.setDescription(option.getDescription()); |
140 |
0 |
copy.setBasicURL(option.getBasicURL()); |
141 |
0 |
copy.setFurtherDetails(option.getFurtherDetails()); |
142 |
0 |
copy.setRequired(option.isRequired()); |
143 |
0 |
List<String> names = option.getOptionNames(); |
144 |
0 |
if (names != null) |
145 |
|
{ |
146 |
0 |
if (names.size() == 1) |
147 |
|
{ |
148 |
0 |
HashSet<String> st = new HashSet(); |
149 |
0 |
st.add(names.get(0)); |
150 |
0 |
copy.setOptionNames(st); |
151 |
|
} |
152 |
|
else |
153 |
|
{ |
154 |
0 |
copy.addOptionNames(names.toArray(new String[] {})); |
155 |
|
} |
156 |
|
} |
157 |
0 |
try |
158 |
|
{ |
159 |
0 |
if (option.getDefaultValue() != null) |
160 |
|
{ |
161 |
0 |
copy.setDefaultValue(option.getDefaultValue()); |
162 |
|
} |
163 |
|
} catch (Exception ex) |
164 |
|
{ |
165 |
0 |
ex.printStackTrace(); |
166 |
|
} |
167 |
|
} |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
169 |
0 |
public static ValueConstrain copyValueConstrain(ValueConstrain vc)... |
170 |
|
{ |
171 |
0 |
try |
172 |
|
{ |
173 |
0 |
ValueConstrain copy = new ValueConstrain(); |
174 |
0 |
if (vc.getMax() != null) |
175 |
|
{ |
176 |
0 |
copy.setMax(vc.getMax().toString()); |
177 |
|
} |
178 |
0 |
if (vc.getMin() != null) |
179 |
|
{ |
180 |
0 |
copy.setMin(vc.getMin().toString()); |
181 |
|
} |
182 |
0 |
if (vc.getType() != null) |
183 |
|
{ |
184 |
0 |
copy.setType(vc.getType()); |
185 |
|
} |
186 |
0 |
return copy; |
187 |
|
} catch (Exception e) |
188 |
|
{ |
189 |
0 |
e.printStackTrace(); |
190 |
0 |
throw new Error(MessageManager.getString( |
191 |
|
"error.implementation_error_couldnt_copy_value_constraint")); |
192 |
|
} |
193 |
|
} |
194 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
195 |
0 |
public static Parameter copyParameter(Parameter parameter)... |
196 |
|
{ |
197 |
0 |
Parameter copy = new Parameter(parameter.getName(), |
198 |
|
parameter.getDescription()); |
199 |
0 |
if (parameter.getValidValue() != null) |
200 |
|
{ |
201 |
0 |
copy.setValidValue(copyValueConstrain(parameter.getValidValue())); |
202 |
|
} |
203 |
0 |
List<String> pv = parameter.getPossibleValues(); |
204 |
0 |
if (pv != null) |
205 |
|
{ |
206 |
0 |
copy.addPossibleValues(pv.toArray(new String[] {})); |
207 |
|
} |
208 |
0 |
setOptionFrom(copy, parameter); |
209 |
0 |
return copy; |
210 |
|
} |
211 |
|
|
212 |
|
} |