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