(int location, int required)
| 405 | } |
| 406 | |
| 407 | private void growForInsert(int location, int required) { |
| 408 | // REVIEW: we grow too quickly because we are called with the |
| 409 | // size of the new collection to add without taking in |
| 410 | // to account the free space we already have |
| 411 | int increment = size / 2; |
| 412 | if (required > increment) { |
| 413 | increment = required; |
| 414 | } |
| 415 | if (increment < 12) { |
| 416 | increment = 12; |
| 417 | } |
| 418 | E[] newArray = newElementArray(size + increment); |
| 419 | // REVIEW: biased towards leaving space at the beginning? |
| 420 | // perhaps newFirst should be (increment-required)/2? |
| 421 | int newFirst = increment - required; |
| 422 | // Copy elements after location to the new array skipping inserted |
| 423 | // elements |
| 424 | System.arraycopy(array, location + firstIndex, newArray, newFirst |
| 425 | + location + required, size - location); |
| 426 | // Copy elements before location to the new array from firstIndex |
| 427 | System.arraycopy(array, firstIndex, newArray, newFirst, location); |
| 428 | firstIndex = newFirst; |
| 429 | array = newArray; |
| 430 | } |
| 431 | |
| 432 | @Override |
| 433 | public int indexOf(Object object) { |
no test coverage detected