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