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 |
|
|
|
|
| 80.4% |
Uncovered Elements: 10 (51) |
Complexity: 12 |
Complexity Density: 0.35 |
|
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 |
|
|
|
|
| 76% |
Uncovered Elements: 6 (25) |
Complexity: 8 |
Complexity Density: 0.53 |
|
47 |
25 |
public static List<int[]> parseLocation(String location)... |
48 |
|
throws ParseException |
49 |
|
{ |
50 |
25 |
location = location.trim(); |
51 |
25 |
if (location.startsWith("join(")) |
52 |
|
{ |
53 |
3 |
return parseJoin(location); |
54 |
|
} |
55 |
22 |
else if (location.startsWith("complement(")) |
56 |
|
{ |
57 |
4 |
return parseComplement(location); |
58 |
|
} |
59 |
18 |
if (location.startsWith("order(")) |
60 |
|
{ |
61 |
0 |
throw new ParseException(location, 0); |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
18 |
String[] range = location.split("\\.\\."); |
68 |
18 |
if (range.length == 1 || range.length == 2) |
69 |
|
{ |
70 |
18 |
try |
71 |
|
{ |
72 |
18 |
int start = Integer.valueOf(range[0]); |
73 |
18 |
int end = range.length == 1 ? start : Integer.valueOf(range[1]); |
74 |
18 |
return Collections.singletonList(new int[] { start, end }); |
75 |
|
} catch (NumberFormatException e) |
76 |
|
{ |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
0 |
throw new ParseException(location, 0); |
81 |
|
} |
82 |
|
} |
83 |
|
else |
84 |
|
{ |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
0 |
throw new ParseException(location, 0); |
89 |
|
} |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
@param |
96 |
|
@return |
97 |
|
@throws |
98 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
99 |
4 |
static List<int[]> parseComplement(String location) throws ParseException... |
100 |
|
{ |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
4 |
if (!location.endsWith(")")) |
105 |
|
{ |
106 |
0 |
throw new ParseException(location, 0); |
107 |
|
} |
108 |
4 |
String toComplement = location.substring("complement(".length(), |
109 |
|
location.length() - 1); |
110 |
4 |
List<int[]> ranges = parseLocation(toComplement); |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
4 |
Collections.reverse(ranges); |
116 |
4 |
for (int[] range : ranges) |
117 |
|
{ |
118 |
4 |
int temp = range[0]; |
119 |
4 |
range[0] = range[1]; |
120 |
4 |
range[1] = temp; |
121 |
|
} |
122 |
4 |
return ranges; |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
@param |
129 |
|
@return |
130 |
|
@throws |
131 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
132 |
3 |
static List<int[]> parseJoin(String location) throws ParseException... |
133 |
|
{ |
134 |
3 |
List<int[]> ranges = new ArrayList<int[]>(); |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
3 |
if (!location.endsWith(")")) |
140 |
|
{ |
141 |
0 |
throw new ParseException(location, 0); |
142 |
|
} |
143 |
3 |
String joinedLocs = location.substring("join(".length(), |
144 |
|
location.length() - 1); |
145 |
3 |
String[] locations = joinedLocs.split(","); |
146 |
3 |
for (String loc : locations) |
147 |
|
{ |
148 |
9 |
List<int[]> range = parseLocation(loc); |
149 |
9 |
ranges.addAll(range); |
150 |
|
} |
151 |
3 |
return ranges; |
152 |
|
} |
153 |
|
|
154 |
|
} |