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.util.ArrayList; |
24 |
|
import java.util.Arrays; |
25 |
|
import java.util.BitSet; |
26 |
|
import java.util.List; |
27 |
|
|
28 |
|
import jalview.bin.Console; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
|
|
| 0% |
Uncovered Elements: 642 (642) |
Complexity: 167 |
Complexity Density: 0.41 |
|
39 |
|
public class MapList |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private List<int[]> fromShifts; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
private List<int[]> toShifts; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
private int fromRatio; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
private int toRatio; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
private int fromLowest; |
66 |
|
|
67 |
|
private int fromHighest; |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
private int toLowest; |
73 |
|
|
74 |
|
private int toHighest; |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
79 |
0 |
public MapList()... |
80 |
|
{ |
81 |
0 |
fromShifts = new ArrayList<>(); |
82 |
0 |
toShifts = new ArrayList<>(); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 8 |
Complexity Density: 1 |
|
89 |
0 |
@Override... |
90 |
|
public boolean equals(Object o) |
91 |
|
{ |
92 |
0 |
if (o == null || !(o instanceof MapList)) |
93 |
|
{ |
94 |
0 |
return false; |
95 |
|
} |
96 |
|
|
97 |
0 |
MapList obj = (MapList) o; |
98 |
0 |
if (obj == this) |
99 |
|
{ |
100 |
0 |
return true; |
101 |
|
} |
102 |
0 |
if (obj.fromRatio != fromRatio || obj.toRatio != toRatio |
103 |
|
|| obj.fromShifts == null || obj.toShifts == null) |
104 |
|
{ |
105 |
0 |
return false; |
106 |
|
} |
107 |
0 |
return Arrays.deepEquals(fromShifts.toArray(), obj.fromShifts.toArray()) |
108 |
|
&& Arrays.deepEquals(toShifts.toArray(), |
109 |
|
obj.toShifts.toArray()); |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
115 |
0 |
@Override... |
116 |
|
public int hashCode() |
117 |
|
{ |
118 |
0 |
int hashCode = 31 * fromRatio; |
119 |
0 |
hashCode = 31 * hashCode + toRatio; |
120 |
0 |
for (int[] shift : fromShifts) |
121 |
|
{ |
122 |
0 |
hashCode = 31 * hashCode + shift[0]; |
123 |
0 |
hashCode = 31 * hashCode + shift[1]; |
124 |
|
} |
125 |
0 |
for (int[] shift : toShifts) |
126 |
|
{ |
127 |
0 |
hashCode = 31 * hashCode + shift[0]; |
128 |
0 |
hashCode = 31 * hashCode + shift[1]; |
129 |
|
} |
130 |
|
|
131 |
0 |
return hashCode; |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
@return |
138 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
139 |
0 |
public List<int[]> getFromRanges()... |
140 |
|
{ |
141 |
0 |
return fromShifts; |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
@return |
148 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
149 |
0 |
public List<int[]> getToRanges()... |
150 |
|
{ |
151 |
0 |
return toShifts; |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
@param |
159 |
|
@return |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
161 |
0 |
protected static int[] getRanges(List<int[]> shifts)... |
162 |
|
{ |
163 |
0 |
int[] rnges = new int[2 * shifts.size()]; |
164 |
0 |
int i = 0; |
165 |
0 |
for (int[] r : shifts) |
166 |
|
{ |
167 |
0 |
rnges[i++] = r[0]; |
168 |
0 |
rnges[i++] = r[1]; |
169 |
|
} |
170 |
0 |
return rnges; |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
@return |
176 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
0 |
public int getFromRatio()... |
178 |
|
{ |
179 |
0 |
return fromRatio; |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
@return |
185 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
186 |
0 |
public int getToRatio()... |
187 |
|
{ |
188 |
0 |
return toRatio; |
189 |
|
} |
190 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
191 |
0 |
public int getFromLowest()... |
192 |
|
{ |
193 |
0 |
return fromLowest; |
194 |
|
} |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
0 |
public int getFromHighest()... |
197 |
|
{ |
198 |
0 |
return fromHighest; |
199 |
|
} |
200 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
201 |
0 |
public int getToLowest()... |
202 |
|
{ |
203 |
0 |
return toLowest; |
204 |
|
} |
205 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
206 |
0 |
public int getToHighest()... |
207 |
|
{ |
208 |
0 |
return toHighest; |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
@param |
216 |
|
|
217 |
|
@param |
218 |
|
|
219 |
|
@param |
220 |
|
|
221 |
|
@param |
222 |
|
|
223 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 3 |
Complexity Density: 0.2 |
|
224 |
0 |
public MapList(int from[], int to[], int fromRatio, int toRatio)... |
225 |
|
{ |
226 |
0 |
this(); |
227 |
0 |
this.fromRatio = fromRatio; |
228 |
0 |
this.toRatio = toRatio; |
229 |
0 |
fromLowest = Integer.MAX_VALUE; |
230 |
0 |
fromHighest = Integer.MIN_VALUE; |
231 |
|
|
232 |
0 |
for (int i = 0; i < from.length; i += 2) |
233 |
|
{ |
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
0 |
fromLowest = Math.min(fromLowest, Math.min(from[i], from[i + 1])); |
239 |
0 |
fromHighest = Math.max(fromHighest, Math.max(from[i], from[i + 1])); |
240 |
0 |
fromShifts.add(new int[] { from[i], from[i + 1] }); |
241 |
|
} |
242 |
|
|
243 |
0 |
toLowest = Integer.MAX_VALUE; |
244 |
0 |
toHighest = Integer.MIN_VALUE; |
245 |
0 |
for (int i = 0; i < to.length; i += 2) |
246 |
|
{ |
247 |
0 |
toLowest = Math.min(toLowest, Math.min(to[i], to[i + 1])); |
248 |
0 |
toHighest = Math.max(toHighest, Math.max(to[i], to[i + 1])); |
249 |
0 |
toShifts.add(new int[] { to[i], to[i + 1] }); |
250 |
|
} |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
@param |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
258 |
0 |
public MapList(MapList map)... |
259 |
|
{ |
260 |
0 |
this(); |
261 |
|
|
262 |
0 |
this.fromLowest = map.fromLowest; |
263 |
0 |
this.fromHighest = map.fromHighest; |
264 |
0 |
this.toLowest = map.toLowest; |
265 |
0 |
this.toHighest = map.toHighest; |
266 |
|
|
267 |
0 |
this.fromRatio = map.fromRatio; |
268 |
0 |
this.toRatio = map.toRatio; |
269 |
0 |
if (map.fromShifts != null) |
270 |
|
{ |
271 |
0 |
for (int[] r : map.fromShifts) |
272 |
|
{ |
273 |
0 |
fromShifts.add(new int[] { r[0], r[1] }); |
274 |
|
} |
275 |
|
} |
276 |
0 |
if (map.toShifts != null) |
277 |
|
{ |
278 |
0 |
for (int[] r : map.toShifts) |
279 |
|
{ |
280 |
0 |
toShifts.add(new int[] { r[0], r[1] }); |
281 |
|
} |
282 |
|
} |
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
@param |
290 |
|
@param |
291 |
|
@param |
292 |
|
@param |
293 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 3 |
Complexity Density: 0.14 |
|
294 |
0 |
public MapList(List<int[]> fromRange, List<int[]> toRange, int fromRatio,... |
295 |
|
int toRatio) |
296 |
|
{ |
297 |
0 |
this(); |
298 |
0 |
fromRange = coalesceRanges(fromRange); |
299 |
0 |
toRange = coalesceRanges(toRange); |
300 |
0 |
this.fromShifts = fromRange; |
301 |
0 |
this.toShifts = toRange; |
302 |
0 |
this.fromRatio = fromRatio; |
303 |
0 |
this.toRatio = toRatio; |
304 |
|
|
305 |
0 |
fromLowest = Integer.MAX_VALUE; |
306 |
0 |
fromHighest = Integer.MIN_VALUE; |
307 |
0 |
for (int[] range : fromRange) |
308 |
|
{ |
309 |
0 |
if (range.length != 2) |
310 |
|
{ |
311 |
|
|
312 |
0 |
Console.error("Invalid format for fromRange " |
313 |
|
+ Arrays.toString(range) + " may cause errors"); |
314 |
|
} |
315 |
0 |
fromLowest = Math.min(fromLowest, Math.min(range[0], range[1])); |
316 |
0 |
fromHighest = Math.max(fromHighest, Math.max(range[0], range[1])); |
317 |
|
} |
318 |
|
|
319 |
0 |
toLowest = Integer.MAX_VALUE; |
320 |
0 |
toHighest = Integer.MIN_VALUE; |
321 |
0 |
for (int[] range : toRange) |
322 |
|
{ |
323 |
0 |
if (range.length != 2) |
324 |
|
{ |
325 |
|
|
326 |
0 |
Console.error("Invalid format for toRange " + Arrays.toString(range) |
327 |
|
+ " may cause errors"); |
328 |
|
} |
329 |
0 |
toLowest = Math.min(toLowest, Math.min(range[0], range[1])); |
330 |
0 |
toHighest = Math.max(toHighest, Math.max(range[0], range[1])); |
331 |
|
} |
332 |
|
} |
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
@param |
350 |
|
@return |
351 |
|
|
352 |
|
|
|
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 10 |
Complexity Density: 0.43 |
|
353 |
0 |
public static List<int[]> coalesceRanges(final List<int[]> ranges)... |
354 |
|
{ |
355 |
0 |
if (ranges == null || ranges.size() < 2) |
356 |
|
{ |
357 |
0 |
return ranges; |
358 |
|
} |
359 |
|
|
360 |
0 |
boolean changed = false; |
361 |
0 |
List<int[]> merged = new ArrayList<>(); |
362 |
0 |
int[] lastRange = ranges.get(0); |
363 |
0 |
int lastDirection = lastRange[1] >= lastRange[0] ? 1 : -1; |
364 |
0 |
lastRange = new int[] { lastRange[0], lastRange[1] }; |
365 |
0 |
merged.add(lastRange); |
366 |
0 |
boolean first = true; |
367 |
|
|
368 |
0 |
for (final int[] range : ranges) |
369 |
|
{ |
370 |
0 |
if (first) |
371 |
|
{ |
372 |
0 |
first = false; |
373 |
0 |
continue; |
374 |
|
} |
375 |
|
|
376 |
0 |
int direction = range[1] >= range[0] ? 1 : -1; |
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
0 |
boolean sameDirection = range[1] == range[0] |
383 |
|
|| direction == lastDirection; |
384 |
0 |
boolean extending = range[0] == lastRange[1] + lastDirection; |
385 |
0 |
if (sameDirection && extending) |
386 |
|
{ |
387 |
0 |
lastRange[1] = range[1]; |
388 |
0 |
changed = true; |
389 |
|
} |
390 |
|
else |
391 |
|
{ |
392 |
0 |
lastRange = new int[] { range[0], range[1] }; |
393 |
0 |
merged.add(lastRange); |
394 |
|
|
395 |
0 |
lastDirection = (range[1] == range[0]) ? lastDirection : direction; |
396 |
|
} |
397 |
|
} |
398 |
|
|
399 |
0 |
return changed ? merged : ranges; |
400 |
|
} |
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
|
405 |
|
@return |
406 |
|
|
407 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
408 |
0 |
protected int[][] makeFromMap()... |
409 |
|
{ |
410 |
|
|
411 |
0 |
return posMap(fromShifts, fromRatio, toShifts, toRatio); |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
|
417 |
|
@return |
418 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
419 |
0 |
protected int[][] makeToMap()... |
420 |
|
{ |
421 |
|
|
422 |
0 |
return posMap(toShifts, toRatio, fromShifts, fromRatio); |
423 |
|
} |
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
@param |
429 |
|
@return |
430 |
|
|
431 |
|
|
|
|
| 0% |
Uncovered Elements: 66 (66) |
Complexity: 15 |
Complexity Density: 0.39 |
|
432 |
0 |
private int[][] posMap(List<int[]> shiftTo, int sourceRatio,... |
433 |
|
List<int[]> shiftFrom, int targetRatio) |
434 |
|
{ |
435 |
|
|
436 |
0 |
int iv = 0, ivSize = shiftTo.size(); |
437 |
0 |
if (iv >= ivSize) |
438 |
|
{ |
439 |
0 |
return null; |
440 |
|
} |
441 |
0 |
int[] intv = shiftTo.get(iv++); |
442 |
0 |
int from = intv[0], to = intv[1]; |
443 |
0 |
if (from > to) |
444 |
|
{ |
445 |
0 |
from = intv[1]; |
446 |
0 |
to = intv[0]; |
447 |
|
} |
448 |
0 |
while (iv < ivSize) |
449 |
|
{ |
450 |
0 |
intv = shiftTo.get(iv++); |
451 |
0 |
if (intv[0] < from) |
452 |
|
{ |
453 |
0 |
from = intv[0]; |
454 |
|
} |
455 |
0 |
if (intv[1] < from) |
456 |
|
{ |
457 |
0 |
from = intv[1]; |
458 |
|
} |
459 |
0 |
if (intv[0] > to) |
460 |
|
{ |
461 |
0 |
to = intv[0]; |
462 |
|
} |
463 |
0 |
if (intv[1] > to) |
464 |
|
{ |
465 |
0 |
to = intv[1]; |
466 |
|
} |
467 |
|
} |
468 |
0 |
int tF = 0, tT = 0; |
469 |
0 |
int mp[][] = new int[to - from + 2][]; |
470 |
0 |
for (int i = 0; i < mp.length; i++) |
471 |
|
{ |
472 |
0 |
int[] m = shift(i + from, shiftTo, sourceRatio, shiftFrom, |
473 |
|
targetRatio); |
474 |
0 |
if (m != null) |
475 |
|
{ |
476 |
0 |
if (i == 0) |
477 |
|
{ |
478 |
0 |
tF = tT = m[0]; |
479 |
|
} |
480 |
|
else |
481 |
|
{ |
482 |
0 |
if (m[0] < tF) |
483 |
|
{ |
484 |
0 |
tF = m[0]; |
485 |
|
} |
486 |
0 |
if (m[0] > tT) |
487 |
|
{ |
488 |
0 |
tT = m[0]; |
489 |
|
} |
490 |
|
} |
491 |
|
} |
492 |
0 |
mp[i] = m; |
493 |
|
} |
494 |
0 |
int[][] map = new int[][] { new int[] { from, to, tF, tT }, |
495 |
|
new int[to - from + 2] }; |
496 |
|
|
497 |
0 |
map[0][2] = tF; |
498 |
0 |
map[0][3] = tT; |
499 |
|
|
500 |
0 |
for (int i = 0; i < mp.length; i++) |
501 |
|
{ |
502 |
0 |
if (mp[i] != null) |
503 |
|
{ |
504 |
0 |
map[1][i] = mp[i][0] - tF; |
505 |
|
} |
506 |
|
else |
507 |
|
{ |
508 |
0 |
map[1][i] = -1; |
509 |
|
} |
510 |
|
} |
511 |
0 |
return map; |
512 |
|
} |
513 |
|
|
514 |
|
|
515 |
|
|
516 |
|
|
517 |
|
@param |
518 |
|
|
519 |
|
@param |
520 |
|
|
521 |
|
|
522 |
|
|
523 |
|
|
524 |
|
|
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
|
529 |
|
|
530 |
|
|
531 |
|
|
532 |
|
@param |
533 |
|
|
534 |
|
@return |
535 |
|
|
536 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
537 |
0 |
public int[] shiftFrom(int pos)... |
538 |
|
{ |
539 |
0 |
return shift(pos, fromShifts, fromRatio, toShifts, toRatio); |
540 |
|
} |
541 |
|
|
542 |
|
|
543 |
|
|
544 |
|
|
545 |
|
@param |
546 |
|
|
547 |
|
@return |
548 |
|
|
549 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
550 |
0 |
public int[] shiftTo(int pos)... |
551 |
|
{ |
552 |
0 |
return shift(pos, toShifts, toRatio, fromShifts, fromRatio); |
553 |
|
} |
554 |
|
|
555 |
|
|
556 |
|
|
557 |
|
@param |
558 |
|
@param |
559 |
|
@param |
560 |
|
@param |
561 |
|
@return |
562 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
563 |
0 |
protected static int[] shift(int pos, List<int[]> shiftTo, int fromRatio,... |
564 |
|
List<int[]> shiftFrom, int toRatio) |
565 |
|
{ |
566 |
|
|
567 |
0 |
int[] fromCount = countPositions(shiftTo, pos); |
568 |
0 |
if (fromCount == null) |
569 |
|
{ |
570 |
0 |
return null; |
571 |
|
} |
572 |
0 |
int fromRemainder = (fromCount[0] - 1) % fromRatio; |
573 |
0 |
int toCount = 1 + (((fromCount[0] - 1) / fromRatio) * toRatio); |
574 |
0 |
int[] toPos = traverseToPosition(shiftFrom, toCount); |
575 |
0 |
if (toPos == null) |
576 |
|
{ |
577 |
0 |
return null; |
578 |
|
} |
579 |
0 |
return new int[] { toPos[0], fromRemainder, toPos[1] }; |
580 |
|
} |
581 |
|
|
582 |
|
|
583 |
|
|
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
|
|
591 |
|
|
592 |
|
@param |
593 |
|
|
594 |
|
@param |
595 |
|
|
596 |
|
@return |
597 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 7 |
Complexity Density: 0.54 |
|
598 |
0 |
protected static int[] countPositions(List<int[]> intervals, int pos)... |
599 |
|
{ |
600 |
0 |
int count = 0; |
601 |
0 |
int iv = 0; |
602 |
0 |
int ivSize = intervals.size(); |
603 |
|
|
604 |
0 |
while (iv < ivSize) |
605 |
|
{ |
606 |
0 |
int[] intv = intervals.get(iv++); |
607 |
0 |
if (intv[0] <= intv[1]) |
608 |
|
{ |
609 |
|
|
610 |
|
|
611 |
|
|
612 |
0 |
if (pos >= intv[0] && pos <= intv[1]) |
613 |
|
{ |
614 |
0 |
return new int[] { count + pos - intv[0] + 1, +1 }; |
615 |
|
} |
616 |
|
else |
617 |
|
{ |
618 |
0 |
count += intv[1] - intv[0] + 1; |
619 |
|
} |
620 |
|
} |
621 |
|
else |
622 |
|
{ |
623 |
|
|
624 |
|
|
625 |
|
|
626 |
0 |
if (pos >= intv[1] && pos <= intv[0]) |
627 |
|
{ |
628 |
0 |
return new int[] { count + intv[0] - pos + 1, -1 }; |
629 |
|
} |
630 |
|
else |
631 |
|
{ |
632 |
0 |
count += intv[0] - intv[1] + 1; |
633 |
|
} |
634 |
|
} |
635 |
|
} |
636 |
0 |
return null; |
637 |
|
} |
638 |
|
|
639 |
|
|
640 |
|
|
641 |
|
|
642 |
|
|
643 |
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
|
@param |
650 |
|
|
651 |
|
@param |
652 |
|
|
653 |
|
@return |
654 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 6 |
Complexity Density: 0.38 |
|
655 |
0 |
protected static int[] traverseToPosition(List<int[]> intervals,... |
656 |
|
final int count) |
657 |
|
{ |
658 |
0 |
int traversed = 0; |
659 |
0 |
int ivSize = intervals.size(); |
660 |
0 |
int iv = 0; |
661 |
|
|
662 |
0 |
if (count < 1) |
663 |
|
{ |
664 |
0 |
return null; |
665 |
|
} |
666 |
|
|
667 |
0 |
while (iv < ivSize) |
668 |
|
{ |
669 |
0 |
int[] intv = intervals.get(iv++); |
670 |
0 |
int diff = intv[1] - intv[0]; |
671 |
0 |
if (diff >= 0) |
672 |
|
{ |
673 |
0 |
if (count <= traversed + 1 + diff) |
674 |
|
{ |
675 |
0 |
return new int[] { intv[0] + (count - traversed - 1), +1 }; |
676 |
|
} |
677 |
|
else |
678 |
|
{ |
679 |
0 |
traversed += 1 + diff; |
680 |
|
} |
681 |
|
} |
682 |
|
else |
683 |
|
{ |
684 |
0 |
if (count <= traversed + 1 - diff) |
685 |
|
{ |
686 |
0 |
return new int[] { intv[0] - (count - traversed - 1), -1 }; |
687 |
|
} |
688 |
|
else |
689 |
|
{ |
690 |
0 |
traversed += 1 - diff; |
691 |
|
} |
692 |
|
} |
693 |
|
} |
694 |
0 |
return null; |
695 |
|
} |
696 |
|
|
697 |
|
|
698 |
|
|
699 |
|
|
700 |
|
|
701 |
|
@param |
702 |
|
@param |
703 |
|
@param |
704 |
|
@param |
705 |
|
@return |
706 |
|
|
707 |
|
|
|
|
| 0% |
Uncovered Elements: 129 (129) |
Complexity: 37 |
Complexity Density: 0.47 |
|
708 |
0 |
protected static int[] getIntervals(List<int[]> shiftFrom,... |
709 |
|
int[] fromStart, int[] fromEnd, int fromRatio2) |
710 |
|
{ |
711 |
0 |
if (fromStart == null || fromEnd == null) |
712 |
|
{ |
713 |
0 |
return null; |
714 |
|
} |
715 |
0 |
int startpos, endpos; |
716 |
0 |
startpos = fromStart[0]; |
717 |
0 |
endpos = fromEnd[0]; |
718 |
0 |
int endindx = (fromRatio2 - 1); |
719 |
|
|
720 |
0 |
int intv = 0, intvSize = shiftFrom.size(); |
721 |
0 |
int iv[], i = 0, fs = -1, fe_s = -1, fe = -1; |
722 |
|
|
723 |
|
|
724 |
0 |
while (intv < intvSize && (fs == -1 || fe == -1)) |
725 |
|
{ |
726 |
0 |
iv = shiftFrom.get(intv++); |
727 |
0 |
if (fe_s > -1) |
728 |
|
{ |
729 |
0 |
endpos = iv[0]; |
730 |
0 |
endindx--; |
731 |
|
} |
732 |
0 |
if (iv[0] <= iv[1]) |
733 |
|
{ |
734 |
0 |
if (fs == -1 && startpos >= iv[0] && startpos <= iv[1]) |
735 |
|
{ |
736 |
0 |
fs = i; |
737 |
|
} |
738 |
0 |
if (endpos >= iv[0] && endpos <= iv[1]) |
739 |
|
{ |
740 |
0 |
if (fe_s == -1) |
741 |
|
{ |
742 |
0 |
fe_s = i; |
743 |
|
} |
744 |
0 |
if (fe_s != -1) |
745 |
|
{ |
746 |
0 |
if (endpos + endindx <= iv[1]) |
747 |
|
{ |
748 |
0 |
fe = i; |
749 |
0 |
endpos = endpos + endindx; |
750 |
|
|
751 |
|
} |
752 |
|
else |
753 |
|
{ |
754 |
0 |
endindx -= iv[1] - endpos; |
755 |
|
} |
756 |
|
} |
757 |
|
} |
758 |
|
} |
759 |
|
else |
760 |
|
{ |
761 |
0 |
if (fs == -1 && startpos <= iv[0] && startpos >= iv[1]) |
762 |
|
{ |
763 |
0 |
fs = i; |
764 |
|
} |
765 |
0 |
if (endpos <= iv[0] && endpos >= iv[1]) |
766 |
|
{ |
767 |
0 |
if (fe_s == -1) |
768 |
|
{ |
769 |
0 |
fe_s = i; |
770 |
|
} |
771 |
0 |
if (fe_s != -1) |
772 |
|
{ |
773 |
0 |
if (endpos - endindx >= iv[1]) |
774 |
|
{ |
775 |
0 |
fe = i; |
776 |
0 |
endpos = endpos - endindx; |
777 |
|
|
778 |
|
} |
779 |
|
else |
780 |
|
{ |
781 |
0 |
endindx -= endpos - iv[1]; |
782 |
|
} |
783 |
|
} |
784 |
|
} |
785 |
|
} |
786 |
0 |
i++; |
787 |
|
} |
788 |
0 |
if (fs == fe && fe == -1) |
789 |
|
{ |
790 |
0 |
return null; |
791 |
|
} |
792 |
0 |
List<int[]> ranges = new ArrayList<>(); |
793 |
0 |
if (fs <= fe) |
794 |
|
{ |
795 |
0 |
intv = fs; |
796 |
0 |
i = fs; |
797 |
|
|
798 |
0 |
iv = shiftFrom.get(intv++); |
799 |
0 |
iv = new int[] { iv[0], iv[1] }; |
800 |
0 |
if (i == fs) |
801 |
|
{ |
802 |
0 |
iv[0] = startpos; |
803 |
|
} |
804 |
0 |
while (i != fe) |
805 |
|
{ |
806 |
0 |
ranges.add(iv); |
807 |
0 |
iv = shiftFrom.get(intv++); |
808 |
0 |
iv = new int[] { iv[0], iv[1] }; |
809 |
0 |
i++; |
810 |
|
} |
811 |
0 |
if (i == fe) |
812 |
|
{ |
813 |
0 |
iv[1] = endpos; |
814 |
|
} |
815 |
0 |
ranges.add(iv); |
816 |
|
} |
817 |
|
else |
818 |
|
{ |
819 |
|
|
820 |
0 |
i = shiftFrom.size() - 1; |
821 |
0 |
while (i > fs) |
822 |
|
{ |
823 |
0 |
i--; |
824 |
|
} |
825 |
0 |
iv = shiftFrom.get(i); |
826 |
0 |
iv = new int[] { iv[1], iv[0] }; |
827 |
|
|
828 |
0 |
if (i == fs) |
829 |
|
{ |
830 |
0 |
iv[0] = startpos; |
831 |
|
} |
832 |
0 |
while (--i != fe) |
833 |
|
{ |
834 |
0 |
ranges.add(iv); |
835 |
0 |
iv = shiftFrom.get(i); |
836 |
0 |
iv = new int[] { iv[1], iv[0] }; |
837 |
|
} |
838 |
0 |
if (i == fe) |
839 |
|
{ |
840 |
|
|
841 |
0 |
iv[1] = endpos; |
842 |
|
} |
843 |
0 |
ranges.add(iv); |
844 |
|
} |
845 |
|
|
846 |
0 |
int[] range = null; |
847 |
0 |
if (ranges != null && ranges.size() > 0) |
848 |
|
{ |
849 |
0 |
range = new int[ranges.size() * 2]; |
850 |
0 |
intv = 0; |
851 |
0 |
intvSize = ranges.size(); |
852 |
0 |
i = 0; |
853 |
0 |
while (intv < intvSize) |
854 |
|
{ |
855 |
0 |
iv = ranges.get(intv); |
856 |
0 |
range[i++] = iv[0]; |
857 |
0 |
range[i++] = iv[1]; |
858 |
0 |
ranges.set(intv++, null); |
859 |
|
} |
860 |
|
} |
861 |
0 |
return range; |
862 |
|
} |
863 |
|
|
864 |
|
|
865 |
|
|
866 |
|
|
867 |
|
@param |
868 |
|
|
869 |
|
@return |
870 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
871 |
0 |
public int getToPosition(int mpos)... |
872 |
|
{ |
873 |
0 |
int[] mp = shiftTo(mpos); |
874 |
0 |
if (mp != null) |
875 |
|
{ |
876 |
0 |
return mp[0]; |
877 |
|
} |
878 |
0 |
return mpos; |
879 |
|
} |
880 |
|
|
881 |
|
|
882 |
|
|
883 |
|
@return |
884 |
|
|
885 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
886 |
0 |
public MapList getInverse()... |
887 |
|
{ |
888 |
0 |
return new MapList(getToRanges(), getFromRanges(), getToRatio(), |
889 |
|
getFromRatio()); |
890 |
|
} |
891 |
|
|
892 |
|
|
893 |
|
|
894 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
895 |
0 |
@Override... |
896 |
|
public String toString() |
897 |
|
{ |
898 |
0 |
StringBuilder sb = new StringBuilder(64); |
899 |
0 |
sb.append("["); |
900 |
0 |
for (int[] shift : fromShifts) |
901 |
|
{ |
902 |
0 |
sb.append(" ").append(Arrays.toString(shift)); |
903 |
|
} |
904 |
0 |
sb.append(" ] "); |
905 |
0 |
sb.append(fromRatio).append(":").append(toRatio); |
906 |
0 |
sb.append(" to ["); |
907 |
0 |
for (int[] shift : toShifts) |
908 |
|
{ |
909 |
0 |
sb.append(" ").append(Arrays.toString(shift)); |
910 |
|
} |
911 |
0 |
sb.append(" ]"); |
912 |
0 |
return sb.toString(); |
913 |
|
} |
914 |
|
|
915 |
|
|
916 |
|
|
917 |
|
|
918 |
|
|
919 |
|
|
920 |
|
@param |
921 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
922 |
0 |
public void addMapList(MapList map)... |
923 |
|
{ |
924 |
0 |
if (this.equals(map)) |
925 |
|
{ |
926 |
0 |
return; |
927 |
|
} |
928 |
0 |
this.fromLowest = Math.min(fromLowest, map.fromLowest); |
929 |
0 |
this.toLowest = Math.min(toLowest, map.toLowest); |
930 |
0 |
this.fromHighest = Math.max(fromHighest, map.fromHighest); |
931 |
0 |
this.toHighest = Math.max(toHighest, map.toHighest); |
932 |
|
|
933 |
0 |
for (int[] range : map.getFromRanges()) |
934 |
|
{ |
935 |
0 |
addRange(range, fromShifts); |
936 |
|
} |
937 |
0 |
for (int[] range : map.getToRanges()) |
938 |
|
{ |
939 |
0 |
addRange(range, toShifts); |
940 |
|
} |
941 |
|
} |
942 |
|
|
943 |
|
|
944 |
|
|
945 |
|
|
946 |
|
|
947 |
|
@param |
948 |
|
@param |
949 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 10 |
Complexity Density: 0.62 |
|
950 |
0 |
static void addRange(int[] range, List<int[]> addTo)... |
951 |
|
{ |
952 |
|
|
953 |
|
|
954 |
|
|
955 |
0 |
if (addTo.size() == 0) |
956 |
|
{ |
957 |
0 |
addTo.add(range); |
958 |
0 |
return; |
959 |
|
} |
960 |
|
|
961 |
0 |
int[] last = addTo.get(addTo.size() - 1); |
962 |
0 |
boolean lastForward = last[1] >= last[0]; |
963 |
0 |
boolean newForward = range[1] >= range[0]; |
964 |
|
|
965 |
|
|
966 |
|
|
967 |
|
|
968 |
0 |
if (lastForward == newForward && last[1] == range[0]) |
969 |
|
{ |
970 |
0 |
last[1] = range[1]; |
971 |
0 |
return; |
972 |
|
} |
973 |
|
|
974 |
|
|
975 |
|
|
976 |
|
|
977 |
0 |
if (lastForward && newForward && range[0] == last[1] + 1) |
978 |
|
{ |
979 |
0 |
last[1] = range[1]; |
980 |
0 |
return; |
981 |
|
} |
982 |
|
|
983 |
|
|
984 |
|
|
985 |
|
|
986 |
0 |
if (!lastForward && !newForward && range[0] == last[1] - 1) |
987 |
|
{ |
988 |
0 |
last[1] = range[1]; |
989 |
0 |
return; |
990 |
|
} |
991 |
|
|
992 |
|
|
993 |
|
|
994 |
|
|
995 |
0 |
addTo.add(range); |
996 |
|
} |
997 |
|
|
998 |
|
|
999 |
|
|
1000 |
|
|
1001 |
|
|
1002 |
|
|
1003 |
|
|
1004 |
|
@return |
1005 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1006 |
0 |
public boolean isFromForwardStrand()... |
1007 |
|
{ |
1008 |
0 |
return isForwardStrand(getFromRanges()); |
1009 |
|
} |
1010 |
|
|
1011 |
|
|
1012 |
|
|
1013 |
|
|
1014 |
|
|
1015 |
|
|
1016 |
|
|
1017 |
|
@return |
1018 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1019 |
0 |
public boolean isToForwardStrand()... |
1020 |
|
{ |
1021 |
0 |
return isForwardStrand(getToRanges()); |
1022 |
|
} |
1023 |
|
|
1024 |
|
|
1025 |
|
|
1026 |
|
|
1027 |
|
|
1028 |
|
@param |
1029 |
|
@return |
1030 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
1031 |
0 |
private boolean isForwardStrand(List<int[]> ranges)... |
1032 |
|
{ |
1033 |
0 |
boolean forwardStrand = true; |
1034 |
0 |
for (int[] range : ranges) |
1035 |
|
{ |
1036 |
0 |
if (range[1] > range[0]) |
1037 |
|
{ |
1038 |
0 |
break; |
1039 |
|
} |
1040 |
0 |
else if (range[1] < range[0]) |
1041 |
|
{ |
1042 |
0 |
forwardStrand = false; |
1043 |
0 |
break; |
1044 |
|
} |
1045 |
|
} |
1046 |
0 |
return forwardStrand; |
1047 |
|
} |
1048 |
|
|
1049 |
|
|
1050 |
|
|
1051 |
|
@return |
1052 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1053 |
0 |
public boolean isTripletMap()... |
1054 |
|
{ |
1055 |
0 |
return (toRatio == 3 && fromRatio == 1) |
1056 |
|
|| (fromRatio == 3 && toRatio == 1); |
1057 |
|
} |
1058 |
|
|
1059 |
|
|
1060 |
|
|
1061 |
|
|
1062 |
|
|
1063 |
|
|
1064 |
|
|
1065 |
|
|
1066 |
|
|
1067 |
|
|
1068 |
|
|
1069 |
|
|
1070 |
|
|
1071 |
|
|
1072 |
|
|
1073 |
|
|
1074 |
|
|
1075 |
|
|
1076 |
|
|
1077 |
|
|
1078 |
|
|
1079 |
|
@param |
1080 |
|
@return |
1081 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 6 |
Complexity Density: 0.29 |
|
1082 |
0 |
public MapList traverse(MapList map)... |
1083 |
|
{ |
1084 |
0 |
if (map == null) |
1085 |
|
{ |
1086 |
0 |
return null; |
1087 |
|
} |
1088 |
|
|
1089 |
|
|
1090 |
|
|
1091 |
|
|
1092 |
|
|
1093 |
|
|
1094 |
|
|
1095 |
|
|
1096 |
|
|
1097 |
|
|
1098 |
0 |
int outFromRatio = getFromRatio() * map.getFromRatio(); |
1099 |
0 |
int outToRatio = getToRatio() * map.getToRatio(); |
1100 |
0 |
int gcd = MathUtils.gcd(outFromRatio, outToRatio); |
1101 |
0 |
outFromRatio /= gcd; |
1102 |
0 |
outToRatio /= gcd; |
1103 |
|
|
1104 |
0 |
List<int[]> toRanges = new ArrayList<>(); |
1105 |
0 |
for (int[] range : getToRanges()) |
1106 |
|
{ |
1107 |
0 |
int fromLength = Math.abs(range[1] - range[0]) + 1; |
1108 |
0 |
int[] transferred = map.locateInTo(range[0], range[1]); |
1109 |
0 |
if (transferred == null || transferred.length % 2 != 0) |
1110 |
|
{ |
1111 |
0 |
return null; |
1112 |
|
} |
1113 |
|
|
1114 |
|
|
1115 |
|
|
1116 |
|
|
1117 |
|
|
1118 |
0 |
int toLength = 0; |
1119 |
0 |
for (int i = 0; i < transferred.length;) |
1120 |
|
{ |
1121 |
0 |
toRanges.add(new int[] { transferred[i], transferred[i + 1] }); |
1122 |
0 |
toLength += Math.abs(transferred[i + 1] - transferred[i]) + 1; |
1123 |
0 |
i += 2; |
1124 |
|
} |
1125 |
|
|
1126 |
|
|
1127 |
|
|
1128 |
|
|
1129 |
0 |
if (fromLength * map.getToRatio() != toLength * map.getFromRatio()) |
1130 |
|
{ |
1131 |
0 |
return null; |
1132 |
|
} |
1133 |
|
} |
1134 |
|
|
1135 |
0 |
return new MapList(getFromRanges(), toRanges, outFromRatio, outToRatio); |
1136 |
|
} |
1137 |
|
|
1138 |
|
|
1139 |
|
|
1140 |
|
|
1141 |
|
|
1142 |
|
@return |
1143 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1144 |
0 |
public boolean isContiguous()... |
1145 |
|
{ |
1146 |
0 |
return fromShifts.size() == 1 && toShifts.size() == 1; |
1147 |
|
} |
1148 |
|
|
1149 |
|
|
1150 |
|
|
1151 |
|
|
1152 |
|
|
1153 |
|
|
1154 |
|
|
1155 |
|
|
1156 |
|
@param |
1157 |
|
@param |
1158 |
|
@return |
1159 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1160 |
0 |
public int[] locateInFrom(int start, int end)... |
1161 |
|
{ |
1162 |
0 |
return mapPositions(start, end, toShifts, fromShifts, toRatio, |
1163 |
|
fromRatio); |
1164 |
|
} |
1165 |
|
|
1166 |
|
|
1167 |
|
|
1168 |
|
|
1169 |
|
|
1170 |
|
|
1171 |
|
|
1172 |
|
@param |
1173 |
|
@param |
1174 |
|
@return |
1175 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1176 |
0 |
public int[] locateInTo(int start, int end)... |
1177 |
|
{ |
1178 |
0 |
return mapPositions(start, end, fromShifts, toShifts, fromRatio, |
1179 |
|
toRatio); |
1180 |
|
} |
1181 |
|
|
1182 |
|
|
1183 |
|
|
1184 |
|
|
1185 |
|
|
1186 |
|
|
1187 |
|
|
1188 |
|
|
1189 |
|
@param |
1190 |
|
@param |
1191 |
|
@param |
1192 |
|
@param |
1193 |
|
@param |
1194 |
|
@param |
1195 |
|
@return |
1196 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
1197 |
0 |
final static int[] mapPositions(int start, int end,... |
1198 |
|
List<int[]> sourceRange, List<int[]> targetRange, |
1199 |
|
int sourceWordLength, int targetWordLength) |
1200 |
|
{ |
1201 |
0 |
if (end < start) |
1202 |
|
{ |
1203 |
0 |
int tmp = end; |
1204 |
0 |
end = start; |
1205 |
0 |
start = tmp; |
1206 |
|
} |
1207 |
|
|
1208 |
|
|
1209 |
|
|
1210 |
|
|
1211 |
|
|
1212 |
0 |
BitSet offsets = getMappedOffsetsForPositions(start, end, sourceRange, |
1213 |
|
sourceWordLength, targetWordLength); |
1214 |
|
|
1215 |
|
|
1216 |
|
|
1217 |
|
|
1218 |
0 |
List<int[]> mapped = getPositionsForOffsets(targetRange, offsets); |
1219 |
|
|
1220 |
|
|
1221 |
0 |
return mapped.isEmpty() ? null : MappingUtils.rangeListToArray(mapped); |
1222 |
|
} |
1223 |
|
|
1224 |
|
|
1225 |
|
|
1226 |
|
|
1227 |
|
|
1228 |
|
|
1229 |
|
|
1230 |
|
|
1231 |
|
|
1232 |
|
|
1233 |
|
|
1234 |
|
|
1235 |
|
|
1236 |
|
|
1237 |
|
|
1238 |
|
|
1239 |
|
|
1240 |
|
|
1241 |
|
|
1242 |
|
|
1243 |
|
|
1244 |
|
|
1245 |
|
|
1246 |
|
|
1247 |
|
|
1248 |
|
|
1249 |
|
@param |
1250 |
|
@param |
1251 |
|
@param |
1252 |
|
@param |
1253 |
|
@param |
1254 |
|
@return |
1255 |
|
|
|
|
| 0% |
Uncovered Elements: 41 (41) |
Complexity: 9 |
Complexity Density: 0.31 |
|
1256 |
0 |
protected final static BitSet getMappedOffsetsForPositions(int start,... |
1257 |
|
int end, List<int[]> sourceRange, int sourceWordLength, |
1258 |
|
int targetWordLength) |
1259 |
|
{ |
1260 |
0 |
BitSet overlaps = new BitSet(); |
1261 |
0 |
int offset = 0; |
1262 |
0 |
final int s1 = sourceRange.size(); |
1263 |
0 |
for (int i = 0; i < s1; i++) |
1264 |
|
{ |
1265 |
0 |
int[] range = sourceRange.get(i); |
1266 |
0 |
final int offset1 = offset; |
1267 |
0 |
int overlapStartOffset = -1; |
1268 |
0 |
int overlapEndOffset = -1; |
1269 |
|
|
1270 |
0 |
if (range[1] >= range[0]) |
1271 |
|
{ |
1272 |
|
|
1273 |
|
|
1274 |
|
|
1275 |
0 |
if (start <= range[1] && end >= range[0]) |
1276 |
|
{ |
1277 |
|
|
1278 |
|
|
1279 |
|
|
1280 |
0 |
int overlapStart = Math.max(start, range[0]); |
1281 |
0 |
overlapStartOffset = offset1 + overlapStart - range[0]; |
1282 |
0 |
int overlapEnd = Math.min(end, range[1]); |
1283 |
0 |
overlapEndOffset = offset1 + overlapEnd - range[0]; |
1284 |
|
} |
1285 |
|
} |
1286 |
|
else |
1287 |
|
{ |
1288 |
|
|
1289 |
|
|
1290 |
|
|
1291 |
0 |
if (start <= range[0] && end >= range[1]) |
1292 |
|
{ |
1293 |
|
|
1294 |
|
|
1295 |
|
|
1296 |
0 |
int overlapStart = Math.max(start, range[1]); |
1297 |
0 |
int overlapEnd = Math.min(end, range[0]); |
1298 |
0 |
overlapStartOffset = offset1 + range[0] - overlapEnd; |
1299 |
0 |
overlapEndOffset = offset1 + range[0] - overlapStart; |
1300 |
|
} |
1301 |
|
} |
1302 |
|
|
1303 |
0 |
if (overlapStartOffset > -1) |
1304 |
|
{ |
1305 |
|
|
1306 |
|
|
1307 |
|
|
1308 |
0 |
if (sourceWordLength != targetWordLength) |
1309 |
|
{ |
1310 |
|
|
1311 |
|
|
1312 |
|
|
1313 |
|
|
1314 |
0 |
overlapStartOffset -= overlapStartOffset % sourceWordLength; |
1315 |
0 |
overlapStartOffset = overlapStartOffset / sourceWordLength |
1316 |
|
* targetWordLength; |
1317 |
|
|
1318 |
|
|
1319 |
|
|
1320 |
|
|
1321 |
|
|
1322 |
0 |
overlapEndOffset -= overlapEndOffset % sourceWordLength; |
1323 |
0 |
overlapEndOffset = overlapEndOffset / sourceWordLength |
1324 |
|
* targetWordLength; |
1325 |
0 |
overlapEndOffset += targetWordLength - 1; |
1326 |
|
} |
1327 |
0 |
overlaps.set(overlapStartOffset, overlapEndOffset + 1); |
1328 |
|
} |
1329 |
0 |
offset += 1 + Math.abs(range[1] - range[0]); |
1330 |
|
} |
1331 |
0 |
return overlaps; |
1332 |
|
} |
1333 |
|
|
1334 |
|
|
1335 |
|
|
1336 |
|
|
1337 |
|
|
1338 |
|
|
1339 |
|
@param |
1340 |
|
@param |
1341 |
|
@return |
1342 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
1343 |
0 |
protected final static List<int[]> getPositionsForOffsets(... |
1344 |
|
List<int[]> targetRange, BitSet offsets) |
1345 |
|
{ |
1346 |
0 |
List<int[]> mapped = new ArrayList<>(); |
1347 |
0 |
if (offsets.isEmpty()) |
1348 |
|
{ |
1349 |
0 |
return mapped; |
1350 |
|
} |
1351 |
|
|
1352 |
|
|
1353 |
|
|
1354 |
|
|
1355 |
0 |
int traversed = 0; |
1356 |
|
|
1357 |
|
|
1358 |
|
|
1359 |
|
|
1360 |
|
|
1361 |
|
|
1362 |
0 |
final int toAdd = offsets.cardinality(); |
1363 |
0 |
int added = 0; |
1364 |
0 |
final int s2 = targetRange.size(); |
1365 |
0 |
for (int i = 0; added < toAdd && i < s2; i++) |
1366 |
|
{ |
1367 |
0 |
int[] range = targetRange.get(i); |
1368 |
0 |
added += addOffsetPositions(mapped, traversed, range, offsets); |
1369 |
0 |
traversed += Math.abs(range[1] - range[0]) + 1; |
1370 |
|
} |
1371 |
0 |
return mapped; |
1372 |
|
} |
1373 |
|
|
1374 |
|
|
1375 |
|
|
1376 |
|
|
1377 |
|
|
1378 |
|
|
1379 |
|
|
1380 |
|
@param |
1381 |
|
@param |
1382 |
|
@param |
1383 |
|
@param |
1384 |
|
@return |
1385 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 6 |
Complexity Density: 0.35 |
|
1386 |
0 |
final static int addOffsetPositions(List<int[]> mapped,... |
1387 |
|
final int mapOffset, final int[] range, final BitSet overlaps) |
1388 |
|
{ |
1389 |
0 |
final int rangeLength = 1 + Math.abs(range[1] - range[0]); |
1390 |
0 |
final int step = range[1] < range[0] ? -1 : 1; |
1391 |
0 |
int offsetStart = 0; |
1392 |
0 |
int added = 0; |
1393 |
|
|
1394 |
0 |
while (offsetStart < rangeLength) |
1395 |
|
{ |
1396 |
|
|
1397 |
|
|
1398 |
|
|
1399 |
|
|
1400 |
0 |
int overlapStart = overlaps.nextSetBit(mapOffset + offsetStart); |
1401 |
0 |
if (overlapStart == -1 || overlapStart - mapOffset >= rangeLength) |
1402 |
|
{ |
1403 |
|
|
1404 |
|
|
1405 |
|
|
1406 |
0 |
return added; |
1407 |
|
} |
1408 |
0 |
overlapStart -= mapOffset; |
1409 |
|
|
1410 |
|
|
1411 |
|
|
1412 |
|
|
1413 |
|
|
1414 |
|
|
1415 |
0 |
int overlapEnd = overlaps.nextClearBit(mapOffset + overlapStart + 1); |
1416 |
0 |
overlapEnd = (overlapEnd == -1) ? rangeLength - 1 |
1417 |
|
: Math.min(rangeLength - 1, overlapEnd - mapOffset - 1); |
1418 |
0 |
int startPosition = range[0] + step * overlapStart; |
1419 |
0 |
int endPosition = range[0] + step * overlapEnd; |
1420 |
0 |
mapped.add(new int[] { startPosition, endPosition }); |
1421 |
0 |
offsetStart = overlapEnd + 1; |
1422 |
0 |
added += Math.abs(endPosition - startPosition) + 1; |
1423 |
|
} |
1424 |
|
|
1425 |
0 |
return added; |
1426 |
|
} |
1427 |
|
|
1428 |
|
|
1429 |
|
|
1430 |
|
|
1431 |
|
|
1432 |
|
|
1433 |
|
@param |
1434 |
|
@param |
1435 |
|
@return |
1436 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
1437 |
0 |
public int[] getOverlapsInFrom(final int begin, final int end)... |
1438 |
|
{ |
1439 |
0 |
int[] overlaps = MappingUtils.findOverlap(toShifts, begin, end); |
1440 |
|
|
1441 |
0 |
return overlaps == null ? null : locateInFrom(overlaps[0], overlaps[1]); |
1442 |
|
} |
1443 |
|
|
1444 |
|
|
1445 |
|
|
1446 |
|
|
1447 |
|
|
1448 |
|
|
1449 |
|
@param |
1450 |
|
@param |
1451 |
|
@return |
1452 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
1453 |
0 |
public int[] getOverlapsInTo(final int begin, final int end)... |
1454 |
|
{ |
1455 |
0 |
int[] overlaps = MappingUtils.findOverlap(fromShifts, begin, end); |
1456 |
|
|
1457 |
0 |
return overlaps == null ? null : locateInTo(overlaps[0], overlaps[1]); |
1458 |
|
} |
1459 |
|
} |