1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel.features; |
22 |
|
|
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Collections; |
25 |
|
import java.util.Comparator; |
26 |
|
import java.util.HashMap; |
27 |
|
import java.util.List; |
28 |
|
import java.util.Map; |
29 |
|
import java.util.Map.Entry; |
30 |
|
import java.util.TreeMap; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
|
|
| 78.3% |
Uncovered Elements: 28 (129) |
Complexity: 38 |
Complexity Density: 0.52 |
|
35 |
|
public class FeatureAttributes |
36 |
|
{ |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
37 |
|
public enum Datatype |
38 |
|
{ |
39 |
|
Character, Number, Mixed |
40 |
|
} |
41 |
|
|
42 |
|
private static FeatureAttributes instance = new FeatureAttributes(); |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
private Map<String, Map<String[], AttributeData>> attributes; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private Comparator<String[]> comparator = new Comparator<String[]>() |
58 |
|
{ |
|
|
| 95.2% |
Uncovered Elements: 1 (21) |
Complexity: 7 |
Complexity Density: 0.64 |
|
59 |
1785089 |
@Override... |
60 |
|
public int compare(String[] o1, String[] o2) |
61 |
|
{ |
62 |
1785089 |
int i = 0; |
63 |
2306438 |
while (i < o1.length || i < o2.length) |
64 |
|
{ |
65 |
1785597 |
if (o2.length <= i) |
66 |
|
{ |
67 |
1 |
return o1.length <= i ? 0 : 1; |
68 |
|
} |
69 |
1785596 |
if (o1.length <= i) |
70 |
|
{ |
71 |
1 |
return -1; |
72 |
|
} |
73 |
1785595 |
int comp = String.CASE_INSENSITIVE_ORDER.compare(o1[i], o2[i]); |
74 |
1785595 |
if (comp != 0) |
75 |
|
{ |
76 |
1264246 |
return comp; |
77 |
|
} |
78 |
521349 |
i++; |
79 |
|
} |
80 |
520841 |
return 0; |
81 |
|
} |
82 |
|
}; |
83 |
|
|
|
|
| 95.7% |
Uncovered Elements: 2 (47) |
Complexity: 19 |
Complexity Density: 0.83 |
|
84 |
|
private class AttributeData |
85 |
|
{ |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
List<String> description; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
float min = 0f; |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
float max = 0f; |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
boolean hasValue = false; |
106 |
|
|
107 |
|
Datatype type; |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
@param |
114 |
|
@param |
115 |
|
|
|
|
| 92.3% |
Uncovered Elements: 2 (26) |
Complexity: 11 |
Complexity Density: 0.79 |
|
116 |
520965 |
void addInstance(String desc, String value)... |
117 |
|
{ |
118 |
520965 |
addDescription(desc); |
119 |
|
|
120 |
520965 |
if (value != null) |
121 |
|
{ |
122 |
520965 |
value = value.trim(); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
520965 |
if (type == null || type == Datatype.Number) |
129 |
|
{ |
130 |
743 |
try |
131 |
|
{ |
132 |
743 |
float f = Float.valueOf(value); |
133 |
607 |
min = hasValue ? Math.min(min, f) : f; |
134 |
607 |
max = hasValue ? Math.max(max, f) : f; |
135 |
607 |
hasValue = true; |
136 |
607 |
type = (type == null || type == Datatype.Number) |
137 |
|
? Datatype.Number |
138 |
|
: Datatype.Mixed; |
139 |
|
} catch (NumberFormatException e) |
140 |
|
{ |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
136 |
type = (type == null || type == Datatype.Character) |
145 |
|
? Datatype.Character |
146 |
|
: Datatype.Mixed; |
147 |
136 |
min = 0f; |
148 |
136 |
max = 0f; |
149 |
136 |
hasValue = false; |
150 |
|
} |
151 |
|
} |
152 |
|
} |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
@return |
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
159 |
2 |
public String getDescription()... |
160 |
|
{ |
161 |
2 |
if (description != null && description.size() == 1) |
162 |
|
{ |
163 |
1 |
return description.get(0); |
164 |
|
} |
165 |
1 |
return null; |
166 |
|
} |
167 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
168 |
3 |
public Datatype getType()... |
169 |
|
{ |
170 |
3 |
return type; |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
@param |
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.8 |
|
179 |
520967 |
public void addDescription(String desc)... |
180 |
|
{ |
181 |
520967 |
if (desc != null) |
182 |
|
{ |
183 |
212 |
if (description == null) |
184 |
|
{ |
185 |
39 |
description = new ArrayList<>(); |
186 |
|
} |
187 |
212 |
if (!description.contains(desc)) |
188 |
|
{ |
189 |
40 |
description.add(desc); |
190 |
|
} |
191 |
|
} |
192 |
|
} |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
@return |
199 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
200 |
520861 |
public static FeatureAttributes getInstance()... |
201 |
|
{ |
202 |
520861 |
return instance; |
203 |
|
} |
204 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
205 |
1 |
private FeatureAttributes()... |
206 |
|
{ |
207 |
1 |
attributes = new HashMap<>(); |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
@param |
217 |
|
@return |
218 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
219 |
0 |
public List<String[]> getAttributes(String featureType)... |
220 |
|
{ |
221 |
0 |
if (!attributes.containsKey(featureType)) |
222 |
|
{ |
223 |
0 |
return Collections.<String[]> emptyList(); |
224 |
|
} |
225 |
|
|
226 |
0 |
return new ArrayList<>(attributes.get(featureType).keySet()); |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
@param |
234 |
|
@return |
235 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
236 |
0 |
public boolean hasAttributes(String featureType)... |
237 |
|
{ |
238 |
0 |
if (attributes.containsKey(featureType)) |
239 |
|
{ |
240 |
0 |
if (!attributes.get(featureType).isEmpty()) |
241 |
|
{ |
242 |
0 |
return true; |
243 |
|
} |
244 |
|
} |
245 |
0 |
return false; |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
@param |
253 |
|
@param |
254 |
|
@param |
255 |
|
@param |
256 |
|
|
|
|
| 92.6% |
Uncovered Elements: 2 (27) |
Complexity: 6 |
Complexity Density: 0.32 |
|
257 |
521026 |
public void addAttribute(String featureType, String description,... |
258 |
|
Object value, String... attName) |
259 |
|
{ |
260 |
521026 |
if (featureType == null || attName == null) |
261 |
|
{ |
262 |
0 |
return; |
263 |
|
} |
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
521026 |
if (value instanceof Map<?, ?>) |
270 |
|
{ |
271 |
61 |
for (Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) |
272 |
|
{ |
273 |
175 |
String[] attNames = new String[attName.length + 1]; |
274 |
175 |
System.arraycopy(attName, 0, attNames, 0, attName.length); |
275 |
175 |
attNames[attName.length] = entry.getKey().toString(); |
276 |
175 |
addAttribute(featureType, description, entry.getValue(), attNames); |
277 |
|
} |
278 |
61 |
return; |
279 |
|
} |
280 |
|
|
281 |
520965 |
String valueAsString = value.toString(); |
282 |
520965 |
Map<String[], AttributeData> atts = attributes.get(featureType); |
283 |
520965 |
if (atts == null) |
284 |
|
{ |
285 |
43 |
atts = new TreeMap<>(comparator); |
286 |
43 |
attributes.put(featureType, atts); |
287 |
|
} |
288 |
520965 |
AttributeData attData = atts.get(attName); |
289 |
520965 |
if (attData == null) |
290 |
|
{ |
291 |
180 |
attData = new AttributeData(); |
292 |
180 |
atts.put(attName, attData); |
293 |
|
} |
294 |
520965 |
attData.addInstance(description, valueAsString); |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
@param |
302 |
|
@param |
303 |
|
@return |
304 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
305 |
3 |
public String getDescription(String featureType, String... attName)... |
306 |
|
{ |
307 |
3 |
String desc = null; |
308 |
3 |
Map<String[], AttributeData> atts = attributes.get(featureType); |
309 |
3 |
if (atts != null) |
310 |
|
{ |
311 |
2 |
AttributeData attData = atts.get(attName); |
312 |
2 |
if (attData != null) |
313 |
|
{ |
314 |
2 |
desc = attData.getDescription(); |
315 |
|
} |
316 |
|
} |
317 |
3 |
return desc; |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
@param |
326 |
|
@param |
327 |
|
@return |
328 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
329 |
7 |
public float[] getMinMax(String featureType, String... attName)... |
330 |
|
{ |
331 |
7 |
Map<String[], AttributeData> atts = attributes.get(featureType); |
332 |
7 |
if (atts != null) |
333 |
|
{ |
334 |
6 |
AttributeData attData = atts.get(attName); |
335 |
6 |
if (attData != null && attData.hasValue) |
336 |
|
{ |
337 |
4 |
return new float[] { attData.min, attData.max }; |
338 |
|
} |
339 |
|
} |
340 |
3 |
return null; |
341 |
|
} |
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
@param |
347 |
|
@param |
348 |
|
@param |
349 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
350 |
2 |
public void addDescription(String featureType, String description,... |
351 |
|
String... attName) |
352 |
|
{ |
353 |
2 |
if (featureType == null || attName == null) |
354 |
|
{ |
355 |
0 |
return; |
356 |
|
} |
357 |
|
|
358 |
2 |
Map<String[], AttributeData> atts = attributes.get(featureType); |
359 |
2 |
if (atts == null) |
360 |
|
{ |
361 |
1 |
atts = new TreeMap<>(comparator); |
362 |
1 |
attributes.put(featureType, atts); |
363 |
|
} |
364 |
2 |
AttributeData attData = atts.get(attName); |
365 |
2 |
if (attData == null) |
366 |
|
{ |
367 |
1 |
attData = new AttributeData(); |
368 |
1 |
atts.put(attName, attData); |
369 |
|
} |
370 |
2 |
attData.addDescription(description); |
371 |
|
} |
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
@param |
378 |
|
@param |
379 |
|
@return |
380 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
381 |
4 |
public Datatype getDatatype(String featureType, String... attName)... |
382 |
|
{ |
383 |
4 |
Map<String[], AttributeData> atts = attributes.get(featureType); |
384 |
4 |
if (atts != null) |
385 |
|
{ |
386 |
3 |
AttributeData attData = atts.get(attName); |
387 |
3 |
if (attData != null) |
388 |
|
{ |
389 |
3 |
return attData.getType(); |
390 |
|
} |
391 |
|
} |
392 |
1 |
return null; |
393 |
|
} |
394 |
|
|
395 |
|
|
396 |
|
|
397 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
398 |
1 |
public void clear()... |
399 |
|
{ |
400 |
1 |
attributes.clear(); |
401 |
|
} |
402 |
|
|
403 |
|
|
404 |
|
|
405 |
|
|
406 |
|
@param |
407 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
408 |
0 |
public void clear(String featureType)... |
409 |
|
{ |
410 |
0 |
Map<String[], AttributeData> map = attributes.get(featureType); |
411 |
0 |
if (map != null) |
412 |
|
{ |
413 |
0 |
map.clear(); |
414 |
|
} |
415 |
|
|
416 |
|
} |
417 |
|
} |