1 |
|
/* |
2 |
< |
* @(#)Vector.java 1.103 05/12/06 |
2 |
> |
* %W% %E% |
3 |
|
* |
4 |
|
* Copyright 2006 Sun Microsystems, Inc. All rights reserved. |
5 |
|
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
43 |
|
* |
44 |
|
* <p>As of the Java 2 platform v1.2, this class was retrofitted to |
45 |
|
* implement the {@link List} interface, making it a member of the |
46 |
< |
* <a href="{@docRoot}/../guide/collections/index.html"> Java |
46 |
> |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> Java |
47 |
|
* Collections Framework</a>. Unlike the new collection |
48 |
|
* implementations, {@code Vector} is synchronized. |
49 |
|
* |
50 |
|
* @author Lee Boynton |
51 |
|
* @author Jonathan Payne |
52 |
< |
* @version 1.103, 12/06/05 |
52 |
> |
* @version %I%, %G% |
53 |
|
* @see Collection |
54 |
|
* @see List |
55 |
|
* @see ArrayList |
1194 |
|
final int parentOffset; // index wrt parent |
1195 |
|
int length; // length of sublist |
1196 |
|
|
1197 |
< |
VectorSubList(Vector<E> base, AbstractList<E> parent, int baseOffset, |
1197 |
> |
VectorSubList(Vector<E> base, AbstractList<E> parent, int baseOffset, |
1198 |
|
int fromIndex, int toIndex) { |
1199 |
|
if (fromIndex < 0) |
1200 |
|
throw new IndexOutOfBoundsException("fromIndex = " + fromIndex); |
1216 |
|
* Returns an IndexOutOfBoundsException with nicer message |
1217 |
|
*/ |
1218 |
|
private IndexOutOfBoundsException indexError(int index) { |
1219 |
< |
return new IndexOutOfBoundsException("Index: " + index + |
1219 |
> |
return new IndexOutOfBoundsException("Index: " + index + |
1220 |
|
", Size: " + length); |
1221 |
|
} |
1222 |
|
|
1277 |
|
synchronized(base) { |
1278 |
|
if (base.modCount != modCount) |
1279 |
|
throw new ConcurrentModificationException(); |
1280 |
< |
parent.removeRange(fromIndex + parentOffset, |
1280 |
> |
parent.removeRange(fromIndex + parentOffset, |
1281 |
|
toIndex + parentOffset); |
1282 |
|
length -= (toIndex-fromIndex); |
1283 |
|
modCount = base.modCount; |
1295 |
|
int cSize = c.size(); |
1296 |
|
if (cSize==0) |
1297 |
|
return false; |
1298 |
< |
|
1298 |
> |
|
1299 |
|
if (base.modCount != modCount) |
1300 |
|
throw new ConcurrentModificationException(); |
1301 |
|
parent.addAll(parentOffset + index, c); |
1322 |
|
} |
1323 |
|
|
1324 |
|
public List<E> subList(int fromIndex, int toIndex) { |
1325 |
< |
return new VectorSubList(base, this, fromIndex + baseOffset, |
1325 |
> |
return new VectorSubList(base, this, fromIndex + baseOffset, |
1326 |
|
fromIndex, toIndex); |
1327 |
|
} |
1328 |
|
|
1331 |
|
return new VectorSubListIterator(this, 0); |
1332 |
|
} |
1333 |
|
} |
1334 |
< |
|
1334 |
> |
|
1335 |
|
public synchronized ListIterator<E> listIterator() { |
1336 |
|
synchronized(base) { |
1337 |
|
return new VectorSubListIterator(this, 0); |
1358 |
|
int fence; // Upper bound on cursor |
1359 |
|
int lastRet; // Index of returned element, or -1 |
1360 |
|
int expectedModCount; // Expected modCount of base Vector |
1361 |
< |
|
1361 |
> |
|
1362 |
|
VectorSubListIterator(VectorSubList<E> list, int index) { |
1363 |
|
this.lastRet = -1; |
1364 |
|
this.cursor = index; |
1368 |
|
this.base = list.base; |
1369 |
|
this.expectedModCount = base.modCount; |
1370 |
|
} |
1371 |
< |
|
1371 |
> |
|
1372 |
|
public boolean hasNext() { |
1373 |
|
return cursor < fence; |
1374 |
|
} |
1375 |
< |
|
1375 |
> |
|
1376 |
|
public boolean hasPrevious() { |
1377 |
|
return cursor > 0; |
1378 |
|
} |
1379 |
< |
|
1379 |
> |
|
1380 |
|
public int nextIndex() { |
1381 |
|
return cursor; |
1382 |
|
} |
1383 |
< |
|
1383 |
> |
|
1384 |
|
public int previousIndex() { |
1385 |
|
return cursor - 1; |
1386 |
|
} |
1387 |
< |
|
1387 |
> |
|
1388 |
|
public E next() { |
1389 |
|
int i = cursor; |
1390 |
|
if (cursor >= fence) |
1394 |
|
cursor = i + 1; |
1395 |
|
return (E)next; |
1396 |
|
} |
1397 |
< |
|
1397 |
> |
|
1398 |
|
public E previous() { |
1399 |
|
int i = cursor - 1; |
1400 |
|
if (i < 0) |
1404 |
|
cursor = i; |
1405 |
|
return (E)prev; |
1406 |
|
} |
1407 |
< |
|
1407 |
> |
|
1408 |
|
public void set(E e) { |
1409 |
|
if (lastRet < 0) |
1410 |
|
throw new IllegalStateException(); |
1417 |
|
throw new ConcurrentModificationException(); |
1418 |
|
} |
1419 |
|
} |
1420 |
< |
|
1420 |
> |
|
1421 |
|
public void remove() { |
1422 |
|
int i = lastRet; |
1423 |
|
if (i < 0) |
1435 |
|
throw new ConcurrentModificationException(); |
1436 |
|
} |
1437 |
|
} |
1438 |
< |
|
1438 |
> |
|
1439 |
|
public void add(E e) { |
1440 |
|
if (base.modCount != expectedModCount) |
1441 |
|
throw new ConcurrentModificationException(); |
1455 |
|
} |
1456 |
|
|
1457 |
|
|
1458 |
< |
|
1458 |
> |
|