354 |
*/ |
*/ |
355 |
public synchronized int lastIndexOf(Object e, int index) |
public synchronized int lastIndexOf(Object e, int index) |
356 |
{ |
{ |
357 |
if (index >= elementCount) |
checkBoundExclusive(index); |
|
throw new IndexOutOfBoundsException(index + " >= " + elementCount); |
|
|
|
|
358 |
for (int i = index; i >= 0; i--) |
for (int i = index; i >= 0; i--) |
359 |
if (equals(e, elementData[i])) |
if (equals(e, elementData[i])) |
360 |
return i; |
return i; |
371 |
*/ |
*/ |
372 |
public synchronized Object elementAt(int index) |
public synchronized Object elementAt(int index) |
373 |
{ |
{ |
374 |
// Within the bounds of this Vector does not necessarily mean within |
checkBoundExclusive(index); |
|
// the bounds of the internal array. |
|
|
if (index >= elementCount) |
|
|
throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount); |
|
|
|
|
375 |
return elementData[index]; |
return elementData[index]; |
376 |
} |
} |
377 |
|
|
440 |
*/ |
*/ |
441 |
public synchronized void insertElementAt(Object obj, int index) |
public synchronized void insertElementAt(Object obj, int index) |
442 |
{ |
{ |
443 |
if (index > elementCount) |
checkBoundInclusive(index); |
|
throw new ArrayIndexOutOfBoundsException(index + " > " + elementCount); |
|
|
|
|
444 |
if (elementCount == elementData.length) |
if (elementCount == elementData.length) |
445 |
ensureCapacity(elementCount + 1); |
ensureCapacity(elementCount + 1); |
446 |
modCount++; |
modCount++; |
590 |
*/ |
*/ |
591 |
public synchronized Object set(int index, Object element) |
public synchronized Object set(int index, Object element) |
592 |
{ |
{ |
593 |
if (index >= elementCount) |
checkBoundExclusive(index); |
|
throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount); |
|
|
|
|
594 |
Object temp = elementData[index]; |
Object temp = elementData[index]; |
595 |
elementData[index] = element; |
elementData[index] = element; |
596 |
return temp; |
return temp; |
646 |
*/ |
*/ |
647 |
public synchronized Object remove(int index) |
public synchronized Object remove(int index) |
648 |
{ |
{ |
649 |
if (index >= elementCount) |
checkBoundExclusive(index); |
|
throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount); |
|
|
|
|
650 |
Object temp = elementData[index]; |
Object temp = elementData[index]; |
651 |
modCount++; |
modCount++; |
652 |
elementCount--; |
elementCount--; |
759 |
*/ |
*/ |
760 |
public synchronized boolean addAll(int index, Collection c) |
public synchronized boolean addAll(int index, Collection c) |
761 |
{ |
{ |
762 |
if (index > elementCount) |
checkBoundInclusive(index); |
|
throw new ArrayIndexOutOfBoundsException(index); |
|
763 |
Iterator itr = c.iterator(); |
Iterator itr = c.iterator(); |
764 |
int csize = c.size(); |
int csize = c.size(); |
765 |
|
|
858 |
Arrays.fill(elementData, elementCount, save, null); |
Arrays.fill(elementData, elementCount, save, null); |
859 |
} |
} |
860 |
} |
} |
861 |
|
|
862 |
|
/** |
863 |
|
* Checks that the index is in the range of possible elements (inclusive). |
864 |
|
* |
865 |
|
* @param index the index to check |
866 |
|
* @throws ArrayIndexOutOfBoundsException if index > size |
867 |
|
*/ |
868 |
|
private void checkBoundInclusive(int index) |
869 |
|
{ |
870 |
|
// Implementation note: we do not check for negative ranges here, since |
871 |
|
// use of a negative index will cause an ArrayIndexOutOfBoundsException |
872 |
|
// with no effort on our part. |
873 |
|
if (index > elementCount) |
874 |
|
throw new ArrayIndexOutOfBoundsException(index + " > " + elementCount); |
875 |
|
} |
876 |
|
|
877 |
|
/** |
878 |
|
* Checks that the index is in the range of existing elements (exclusive). |
879 |
|
* |
880 |
|
* @param index the index to check |
881 |
|
* @throws ArrayIndexOutOfBoundsException if index >= size |
882 |
|
*/ |
883 |
|
private void checkBoundExclusive(int index) |
884 |
|
{ |
885 |
|
// Implementation note: we do not check for negative ranges here, since |
886 |
|
// use of a negative index will cause an ArrayIndexOutOfBoundsException |
887 |
|
// with no effort on our part. |
888 |
|
if (index >= elementCount) |
889 |
|
throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount); |
890 |
|
} |
891 |
} |
} |