1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ext.android; |
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@link@link |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
|
|
| 42.9% |
Uncovered Elements: 101 (177) |
Complexity: 42 |
Complexity Density: 0.35 |
|
73 |
|
public class SparseShortArray implements Cloneable |
74 |
|
{ |
75 |
|
private short[] mKeys; |
76 |
|
|
77 |
|
private short[] mValues; |
78 |
|
|
79 |
|
private int mSize; |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
2 |
public SparseShortArray()... |
85 |
|
{ |
86 |
2 |
this(10); |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
|
|
| 66.7% |
Uncovered Elements: 3 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
96 |
94 |
public SparseShortArray(int initialCapacity)... |
97 |
|
{ |
98 |
94 |
if (initialCapacity == 0) |
99 |
|
{ |
100 |
0 |
mKeys = new short[0]; |
101 |
0 |
mValues = new short[0]; |
102 |
|
} |
103 |
|
else |
104 |
|
{ |
105 |
94 |
initialCapacity = idealShortArraySize(initialCapacity); |
106 |
94 |
mKeys = new short[initialCapacity]; |
107 |
94 |
mValues = new short[initialCapacity]; |
108 |
|
} |
109 |
94 |
mSize = 0; |
110 |
|
} |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
112 |
0 |
@Override... |
113 |
|
public SparseShortArray clone() |
114 |
|
{ |
115 |
0 |
SparseShortArray clone = null; |
116 |
0 |
try |
117 |
|
{ |
118 |
0 |
clone = (SparseShortArray) super.clone(); |
119 |
0 |
clone.mKeys = mKeys.clone(); |
120 |
0 |
clone.mValues = mValues.clone(); |
121 |
|
} catch (CloneNotSupportedException cnse) |
122 |
|
{ |
123 |
|
|
124 |
|
} |
125 |
0 |
return clone; |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
9 |
public int get(int key)... |
133 |
|
{ |
134 |
9 |
return get(key, 0); |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
@throws |
142 |
|
|
143 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
144 |
9 |
public int get(int key, int valueIfKeyNotFound)... |
145 |
|
{ |
146 |
9 |
checkOverflow(key); |
147 |
9 |
int i = ContainerHelpers.binarySearch(mKeys, mSize, (short) key); |
148 |
9 |
if (i < 0) |
149 |
|
{ |
150 |
0 |
return valueIfKeyNotFound; |
151 |
|
} |
152 |
|
else |
153 |
|
{ |
154 |
9 |
return mValues[i]; |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
@throws |
162 |
|
|
163 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
164 |
0 |
public void delete(int key)... |
165 |
|
{ |
166 |
0 |
checkOverflow(key); |
167 |
0 |
int i = ContainerHelpers.binarySearch(mKeys, mSize, (short) key); |
168 |
0 |
if (i >= 0) |
169 |
|
{ |
170 |
0 |
removeAt(i); |
171 |
|
} |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
177 |
0 |
public void removeAt(int index)... |
178 |
|
{ |
179 |
0 |
System.arraycopy(mKeys, index + 1, mKeys, index, mSize - (index + 1)); |
180 |
0 |
System.arraycopy(mValues, index + 1, mValues, index, |
181 |
|
mSize - (index + 1)); |
182 |
0 |
mSize--; |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
@throws |
190 |
|
|
191 |
|
|
|
|
| 69.2% |
Uncovered Elements: 8 (26) |
Complexity: 4 |
Complexity Density: 0.2 |
|
192 |
21 |
public void put(int key, int value)... |
193 |
|
{ |
194 |
21 |
checkOverflow(key); |
195 |
19 |
checkOverflow(value); |
196 |
17 |
int i = ContainerHelpers.binarySearch(mKeys, mSize, (short) key); |
197 |
17 |
if (i >= 0) |
198 |
|
{ |
199 |
2 |
mValues[i] = (short) value; |
200 |
|
} |
201 |
|
else |
202 |
|
{ |
203 |
15 |
i = ~i; |
204 |
15 |
if (mSize >= mKeys.length) |
205 |
|
{ |
206 |
0 |
int n = idealShortArraySize(mSize + 1); |
207 |
0 |
short[] nkeys = new short[n]; |
208 |
0 |
short[] nvalues = new short[n]; |
209 |
|
|
210 |
0 |
System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length); |
211 |
0 |
System.arraycopy(mValues, 0, nvalues, 0, mValues.length); |
212 |
0 |
mKeys = nkeys; |
213 |
0 |
mValues = nvalues; |
214 |
|
} |
215 |
15 |
if (mSize - i != 0) |
216 |
|
{ |
217 |
|
|
218 |
4 |
System.arraycopy(mKeys, i, mKeys, i + 1, mSize - i); |
219 |
4 |
System.arraycopy(mValues, i, mValues, i + 1, mSize - i); |
220 |
|
} |
221 |
15 |
mKeys[i] = (short) key; |
222 |
15 |
mValues[i] = (short) value; |
223 |
15 |
mSize++; |
224 |
|
} |
225 |
|
} |
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
231 |
260 |
public int size()... |
232 |
|
{ |
233 |
260 |
return mSize; |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
247 |
110 |
public short keyAt(int index)... |
248 |
|
{ |
249 |
110 |
return mKeys[index]; |
250 |
|
} |
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
265 |
112 |
public short valueAt(int index)... |
266 |
|
{ |
267 |
112 |
return mValues[index]; |
268 |
|
} |
269 |
|
|
270 |
|
|
271 |
|
@link |
272 |
|
|
273 |
|
|
274 |
|
@throws |
275 |
|
|
276 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
277 |
0 |
public int indexOfKey(int key)... |
278 |
|
{ |
279 |
0 |
checkOverflow(key); |
280 |
0 |
return ContainerHelpers.binarySearch(mKeys, mSize, (short) key); |
281 |
|
} |
282 |
|
|
283 |
|
|
284 |
|
@link |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
289 |
0 |
public int indexOfValue(int value)... |
290 |
|
{ |
291 |
0 |
for (int i = 0; i < mSize; i++) |
292 |
|
{ |
293 |
0 |
if (mValues[i] == value) |
294 |
|
{ |
295 |
0 |
return i; |
296 |
|
} |
297 |
|
} |
298 |
0 |
return -1; |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
304 |
0 |
public void clear()... |
305 |
|
{ |
306 |
0 |
mSize = 0; |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 4 |
Complexity Density: 0.24 |
|
313 |
0 |
public void append(int key, int value)... |
314 |
|
{ |
315 |
0 |
if (mSize != 0 && key <= mKeys[mSize - 1]) |
316 |
|
{ |
317 |
0 |
put(key, value); |
318 |
0 |
return; |
319 |
|
} |
320 |
0 |
int pos = mSize; |
321 |
0 |
if (pos >= mKeys.length) |
322 |
|
{ |
323 |
0 |
int n = idealShortArraySize(pos + 1); |
324 |
0 |
short[] nkeys = new short[n]; |
325 |
0 |
short[] nvalues = new short[n]; |
326 |
|
|
327 |
0 |
System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length); |
328 |
0 |
System.arraycopy(mValues, 0, nvalues, 0, mValues.length); |
329 |
0 |
mKeys = nkeys; |
330 |
0 |
mValues = nvalues; |
331 |
|
} |
332 |
0 |
checkOverflow(key); |
333 |
0 |
checkOverflow(value); |
334 |
0 |
mKeys[pos] = (short) key; |
335 |
0 |
mValues[pos] = (short) value; |
336 |
0 |
mSize = pos + 1; |
337 |
|
} |
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
@param |
343 |
|
@throws |
344 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
345 |
285 |
public static void checkOverflow(int value)... |
346 |
|
{ |
347 |
285 |
if (value > Short.MAX_VALUE || value < Short.MIN_VALUE) |
348 |
|
{ |
349 |
8 |
throw new ArithmeticException(String.valueOf(value)); |
350 |
|
} |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
@param |
357 |
|
@return |
358 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
359 |
94 |
public static int idealShortArraySize(int need)... |
360 |
|
{ |
361 |
94 |
return idealByteArraySize(need * 2) / 2; |
362 |
|
} |
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
@param |
368 |
|
@return |
369 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
370 |
94 |
public static int idealByteArraySize(int need)... |
371 |
|
{ |
372 |
101 |
for (int i = 4; i < 32; i++) |
373 |
|
{ |
374 |
101 |
if (need <= (1 << i) - 12) |
375 |
|
{ |
376 |
94 |
return (1 << i) - 12; |
377 |
|
} |
378 |
|
} |
379 |
|
|
380 |
0 |
return need; |
381 |
|
} |
382 |
|
|
383 |
|
|
384 |
|
@inheritDoc |
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
389 |
0 |
@Override... |
390 |
|
public String toString() |
391 |
|
{ |
392 |
0 |
if (size() <= 0) |
393 |
|
{ |
394 |
0 |
return "{}"; |
395 |
|
} |
396 |
0 |
StringBuilder buffer = new StringBuilder(mSize * 28); |
397 |
0 |
buffer.append('{'); |
398 |
0 |
for (int i = 0; i < mSize; i++) |
399 |
|
{ |
400 |
0 |
if (i > 0) |
401 |
|
{ |
402 |
0 |
buffer.append(", "); |
403 |
|
} |
404 |
0 |
int key = keyAt(i); |
405 |
0 |
buffer.append(key); |
406 |
0 |
buffer.append('='); |
407 |
0 |
int value = valueAt(i); |
408 |
0 |
buffer.append(value); |
409 |
|
} |
410 |
0 |
buffer.append('}'); |
411 |
0 |
return buffer.toString(); |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
|
417 |
|
|
418 |
|
|
419 |
|
@param |
420 |
|
|
421 |
|
@return |
422 |
|
@throws |
423 |
|
|
424 |
|
|
425 |
|
|
|
|
| 63.3% |
Uncovered Elements: 11 (30) |
Complexity: 4 |
Complexity Density: 0.17 |
|
426 |
118 |
public int add(int key, int toAdd)... |
427 |
|
{ |
428 |
118 |
int newValue = toAdd; |
429 |
118 |
checkOverflow(key); |
430 |
118 |
int i = ContainerHelpers.binarySearch(mKeys, mSize, (short) key); |
431 |
118 |
if (i >= 0) |
432 |
|
{ |
433 |
29 |
checkOverflow(toAdd + mValues[i]); |
434 |
25 |
mValues[i] += (short) toAdd; |
435 |
25 |
newValue = mValues[i]; |
436 |
|
} |
437 |
|
else |
438 |
|
{ |
439 |
89 |
checkOverflow(toAdd); |
440 |
89 |
i = ~i; |
441 |
89 |
if (mSize >= mKeys.length) |
442 |
|
{ |
443 |
0 |
int n = idealShortArraySize(mSize + 1); |
444 |
0 |
short[] nkeys = new short[n]; |
445 |
0 |
short[] nvalues = new short[n]; |
446 |
0 |
System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length); |
447 |
0 |
System.arraycopy(mValues, 0, nvalues, 0, mValues.length); |
448 |
0 |
mKeys = nkeys; |
449 |
0 |
mValues = nvalues; |
450 |
|
} |
451 |
89 |
if (mSize - i != 0) |
452 |
|
{ |
453 |
0 |
System.arraycopy(mKeys, i, mKeys, i + 1, mSize - i); |
454 |
0 |
System.arraycopy(mValues, i, mValues, i + 1, mSize - i); |
455 |
|
} |
456 |
89 |
mKeys[i] = (short) key; |
457 |
89 |
mValues[i] = (short) toAdd; |
458 |
89 |
mSize++; |
459 |
|
} |
460 |
114 |
return newValue; |
461 |
|
} |
462 |
|
} |