src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java

Print this page




1383 
1384         public ListIterator<E> listIterator(int index) {
1385             final ReentrantLock lock = l.lock;
1386             lock.lock();
1387             try {
1388                 checkForComodification();
1389                 if (index < 0 || index > size)
1390                     throw new IndexOutOfBoundsException("Index: "+index+
1391                                                         ", Size: "+size);
1392                 return new COWSubListIterator<E>(l, index, offset, size);
1393             } finally {
1394                 lock.unlock();
1395             }
1396         }
1397 
1398         public List<E> subList(int fromIndex, int toIndex) {
1399             final ReentrantLock lock = l.lock;
1400             lock.lock();
1401             try {
1402                 checkForComodification();
1403                 if (fromIndex < 0 || toIndex > size)
1404                     throw new IndexOutOfBoundsException();
1405                 return new COWSubList<E>(l, fromIndex + offset,
1406                                          toIndex + offset);
1407             } finally {
1408                 lock.unlock();
1409             }
1410         }
1411 
1412         public void forEach(Consumer<? super E> action) {
1413             if (action == null) throw new NullPointerException();
1414             int lo = offset;
1415             int hi = offset + size;
1416             Object[] a = expectedArray;
1417             if (l.getArray() != a)
1418                 throw new ConcurrentModificationException();
1419             if (lo < 0 || hi > a.length)
1420                 throw new IndexOutOfBoundsException();
1421             for (int i = lo; i < hi; ++i) {
1422                 @SuppressWarnings("unchecked") E e = (E) a[i];
1423                 action.accept(e);




1383 
1384         public ListIterator<E> listIterator(int index) {
1385             final ReentrantLock lock = l.lock;
1386             lock.lock();
1387             try {
1388                 checkForComodification();
1389                 if (index < 0 || index > size)
1390                     throw new IndexOutOfBoundsException("Index: "+index+
1391                                                         ", Size: "+size);
1392                 return new COWSubListIterator<E>(l, index, offset, size);
1393             } finally {
1394                 lock.unlock();
1395             }
1396         }
1397 
1398         public List<E> subList(int fromIndex, int toIndex) {
1399             final ReentrantLock lock = l.lock;
1400             lock.lock();
1401             try {
1402                 checkForComodification();
1403                 if (fromIndex < 0 || toIndex > size || fromIndex > toIndex)
1404                     throw new IndexOutOfBoundsException();
1405                 return new COWSubList<E>(l, fromIndex + offset,
1406                                          toIndex + offset);
1407             } finally {
1408                 lock.unlock();
1409             }
1410         }
1411 
1412         public void forEach(Consumer<? super E> action) {
1413             if (action == null) throw new NullPointerException();
1414             int lo = offset;
1415             int hi = offset + size;
1416             Object[] a = expectedArray;
1417             if (l.getArray() != a)
1418                 throw new ConcurrentModificationException();
1419             if (lo < 0 || hi > a.length)
1420                 throw new IndexOutOfBoundsException();
1421             for (int i = lo; i < hi; ++i) {
1422                 @SuppressWarnings("unchecked") E e = (E) a[i];
1423                 action.accept(e);