1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import java.text.ParseException; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Collections; |
26 |
|
import java.util.List; |
27 |
|
|
|
|
| 96% |
Uncovered Elements: 2 (50) |
Complexity: 12 |
Complexity Density: 0.36 |
|
28 |
|
public class DnaUtils |
29 |
|
{ |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@param |
40 |
|
@return |
41 |
|
@throws |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@see |
46 |
|
|
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 8 |
Complexity Density: 0.57 |
|
47 |
52 |
public static List<int[]> parseLocation(String location)... |
48 |
|
throws ParseException |
49 |
|
{ |
50 |
51 |
if (location.startsWith("join(")) |
51 |
|
{ |
52 |
11 |
return parseJoin(location); |
53 |
|
} |
54 |
40 |
else if (location.startsWith("complement(")) |
55 |
|
{ |
56 |
11 |
return parseComplement(location); |
57 |
|
} |
58 |
29 |
if (location.startsWith("order(")) |
59 |
|
{ |
60 |
1 |
throw new ParseException(location, 0); |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
28 |
String[] range = location.split("\\.\\."); |
67 |
28 |
if (range.length == 1 || range.length == 2) |
68 |
|
{ |
69 |
28 |
try |
70 |
|
{ |
71 |
28 |
int start = Integer.valueOf(range[0]); |
72 |
23 |
int end = range.length == 1 ? start : Integer.valueOf(range[1]); |
73 |
22 |
return Collections.singletonList(new int[] { start, end }); |
74 |
|
} catch (NumberFormatException e) |
75 |
|
{ |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
6 |
throw new ParseException(location, 0); |
80 |
|
} |
81 |
|
} |
82 |
|
else |
83 |
|
{ |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
0 |
throw new ParseException(location, 0); |
88 |
|
} |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
@param |
95 |
|
@return |
96 |
|
@throws |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
98 |
11 |
static List<int[]> parseComplement(String location) throws ParseException... |
99 |
|
{ |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
11 |
if (!location.endsWith(")")) |
104 |
|
{ |
105 |
3 |
throw new ParseException(location, 0); |
106 |
|
} |
107 |
8 |
String toComplement = location.substring("complement(".length(), |
108 |
|
location.length() - 1); |
109 |
8 |
List<int[]> ranges = parseLocation(toComplement); |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
8 |
Collections.reverse(ranges); |
115 |
8 |
for (int[] range : ranges) |
116 |
|
{ |
117 |
9 |
int temp = range[0]; |
118 |
9 |
range[0] = range[1]; |
119 |
9 |
range[1] = temp; |
120 |
|
} |
121 |
8 |
return ranges; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@param |
128 |
|
@return |
129 |
|
@throws |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
131 |
11 |
static List<int[]> parseJoin(String location) throws ParseException... |
132 |
|
{ |
133 |
11 |
List<int[]> ranges = new ArrayList<int[]>(); |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
11 |
if (!location.endsWith(")")) |
139 |
|
{ |
140 |
3 |
throw new ParseException(location, 0); |
141 |
|
} |
142 |
8 |
String joinedLocs = location.substring("join(".length(), |
143 |
|
location.length() - 1); |
144 |
8 |
String[] locations = joinedLocs.split(","); |
145 |
8 |
for (String loc : locations) |
146 |
|
{ |
147 |
19 |
List<int[]> range = parseLocation(loc); |
148 |
17 |
ranges.addAll(range); |
149 |
|
} |
150 |
6 |
return ranges; |
151 |
|
} |
152 |
|
|
153 |
|
} |