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