294 |
*/ |
*/ |
295 |
public Object get(int index) |
public Object get(int index) |
296 |
{ |
{ |
297 |
rangeExclusive(index); |
checkBoundExclusive(index); |
298 |
return data[index]; |
return data[index]; |
299 |
} |
} |
300 |
|
|
308 |
*/ |
*/ |
309 |
public Object set(int index, Object e) |
public Object set(int index, Object e) |
310 |
{ |
{ |
311 |
rangeExclusive(index); |
checkBoundExclusive(index); |
312 |
Object result = data[index]; |
Object result = data[index]; |
313 |
data[index] = e; |
data[index] = e; |
314 |
return result; |
return result; |
339 |
*/ |
*/ |
340 |
public void add(int index, Object e) |
public void add(int index, Object e) |
341 |
{ |
{ |
342 |
rangeInclusive(index); |
checkBoundInclusive(index); |
343 |
modCount++; |
modCount++; |
344 |
if (size == data.length) |
if (size == data.length) |
345 |
ensureCapacity(size + 1); |
ensureCapacity(size + 1); |
358 |
*/ |
*/ |
359 |
public Object remove(int index) |
public Object remove(int index) |
360 |
{ |
{ |
361 |
rangeExclusive(index); |
checkBoundExclusive(index); |
362 |
Object r = data[index]; |
Object r = data[index]; |
363 |
modCount++; |
modCount++; |
364 |
if (index != --size) |
if (index != --size) |
407 |
*/ |
*/ |
408 |
public boolean addAll(int index, Collection c) |
public boolean addAll(int index, Collection c) |
409 |
{ |
{ |
410 |
rangeInclusive(index); |
checkBoundInclusive(index); |
411 |
Iterator itr = c.iterator(); |
Iterator itr = c.iterator(); |
412 |
int csize = c.size(); |
int csize = c.size(); |
413 |
|
|
444 |
* Checks that the index is in the range of possible elements (inclusive). |
* Checks that the index is in the range of possible elements (inclusive). |
445 |
* |
* |
446 |
* @param index the index to check |
* @param index the index to check |
447 |
* @throws IndexOutOfBoundsException if index < 0 || index > size |
* @throws IndexOutOfBoundsException if index > size |
448 |
*/ |
*/ |
449 |
private void rangeInclusive(int index) |
private void checkBoundInclusive(int index) |
450 |
{ |
{ |
451 |
// Implementation note: we do not check for negative ranges here, since |
// Implementation note: we do not check for negative ranges here, since |
452 |
// that will cause an ArrayIndexOutOfBoundsException, a subclass of |
// use of a negative index will cause an ArrayIndexOutOfBoundsException, |
453 |
// the required exception, with no effort on our part. |
// a subclass of the required exception, with no effort on our part. |
454 |
if (index > size) |
if (index > size) |
455 |
throw new IndexOutOfBoundsException("Index: " + index + ", Size:" |
throw new IndexOutOfBoundsException("Index: " + index + ", Size:" |
456 |
+ size); |
+ size); |
460 |
* Checks that the index is in the range of existing elements (exclusive). |
* Checks that the index is in the range of existing elements (exclusive). |
461 |
* |
* |
462 |
* @param index the index to check |
* @param index the index to check |
463 |
* @throws IndexOutOfBoundsException if index < 0 || index >= size |
* @throws IndexOutOfBoundsException if index >= size |
464 |
*/ |
*/ |
465 |
private void rangeExclusive(int index) |
private void checkBoundExclusive(int index) |
466 |
{ |
{ |
467 |
// Implementation note: we do not check for negative ranges here, since |
// Implementation note: we do not check for negative ranges here, since |
468 |
// that will cause an ArrayIndexOutOfBoundsException, a subclass of |
// use of a negative index will cause an ArrayIndexOutOfBoundsException, |
469 |
// the required exception, with no effort on our part. |
// a subclass of the required exception, with no effort on our part. |
470 |
if (index >= size) |
if (index >= size) |
471 |
throw new IndexOutOfBoundsException("Index: " + index + ", Size:" |
throw new IndexOutOfBoundsException("Index: " + index + ", Size:" |
472 |
+ size); |
+ size); |