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

Print this page
rev 6977 : [mq]: iterator


1042             throw new UnsupportedOperationException();
1043         }
1044 
1045         /**
1046          * Not supported. Always throws UnsupportedOperationException.
1047          * @throws UnsupportedOperationException always; <tt>set</tt>
1048          *         is not supported by this iterator.
1049          */
1050         public void set(E e) {
1051             throw new UnsupportedOperationException();
1052         }
1053 
1054         /**
1055          * Not supported. Always throws UnsupportedOperationException.
1056          * @throws UnsupportedOperationException always; <tt>add</tt>
1057          *         is not supported by this iterator.
1058          */
1059         public void add(E e) {
1060             throw new UnsupportedOperationException();
1061         }











1062     }
1063 
1064     /**
1065      * Returns a view of the portion of this list between
1066      * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.
1067      * The returned list is backed by this list, so changes in the
1068      * returned list are reflected in this list.
1069      *
1070      * <p>The semantics of the list returned by this method become
1071      * undefined if the backing list (i.e., this list) is modified in
1072      * any way other than via the returned list.
1073      *
1074      * @param fromIndex low endpoint (inclusive) of the subList
1075      * @param toIndex high endpoint (exclusive) of the subList
1076      * @return a view of the specified range within this list
1077      * @throws IndexOutOfBoundsException {@inheritDoc}
1078      */
1079     public List<E> subList(int fromIndex, int toIndex) {
1080         final ReentrantLock lock = this.lock;
1081         lock.lock();


1349         }
1350 
1351         public int nextIndex() {
1352             return it.nextIndex() - offset;
1353         }
1354 
1355         public int previousIndex() {
1356             return it.previousIndex() - offset;
1357         }
1358 
1359         public void remove() {
1360             throw new UnsupportedOperationException();
1361         }
1362 
1363         public void set(E e) {
1364             throw new UnsupportedOperationException();
1365         }
1366 
1367         public void add(E e) {
1368             throw new UnsupportedOperationException();









1369         }
1370     }
1371 
1372     // Support for resetting lock while deserializing
1373     private void resetLock() {
1374         UNSAFE.putObjectVolatile(this, lockOffset, new ReentrantLock());
1375     }
1376     private static final sun.misc.Unsafe UNSAFE;
1377     private static final long lockOffset;
1378     static {
1379         try {
1380             UNSAFE = sun.misc.Unsafe.getUnsafe();
1381             Class<?> k = CopyOnWriteArrayList.class;
1382             lockOffset = UNSAFE.objectFieldOffset
1383                 (k.getDeclaredField("lock"));
1384         } catch (Exception e) {
1385             throw new Error(e);
1386         }
1387     }
1388 




1042             throw new UnsupportedOperationException();
1043         }
1044 
1045         /**
1046          * Not supported. Always throws UnsupportedOperationException.
1047          * @throws UnsupportedOperationException always; <tt>set</tt>
1048          *         is not supported by this iterator.
1049          */
1050         public void set(E e) {
1051             throw new UnsupportedOperationException();
1052         }
1053 
1054         /**
1055          * Not supported. Always throws UnsupportedOperationException.
1056          * @throws UnsupportedOperationException always; <tt>add</tt>
1057          *         is not supported by this iterator.
1058          */
1059         public void add(E e) {
1060             throw new UnsupportedOperationException();
1061         }
1062 
1063         @Override
1064         @SuppressWarnings("unchecked")
1065         public void forEachRemaining(Consumer<? super E> action) {
1066             Objects.requireNonNull(action);
1067             final int size = snapshot.length;
1068             for (int i=cursor; i < size; i++) {
1069                 action.accept((E) snapshot[i]);
1070             }
1071             cursor = size;
1072         }
1073     }
1074 
1075     /**
1076      * Returns a view of the portion of this list between
1077      * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.
1078      * The returned list is backed by this list, so changes in the
1079      * returned list are reflected in this list.
1080      *
1081      * <p>The semantics of the list returned by this method become
1082      * undefined if the backing list (i.e., this list) is modified in
1083      * any way other than via the returned list.
1084      *
1085      * @param fromIndex low endpoint (inclusive) of the subList
1086      * @param toIndex high endpoint (exclusive) of the subList
1087      * @return a view of the specified range within this list
1088      * @throws IndexOutOfBoundsException {@inheritDoc}
1089      */
1090     public List<E> subList(int fromIndex, int toIndex) {
1091         final ReentrantLock lock = this.lock;
1092         lock.lock();


1360         }
1361 
1362         public int nextIndex() {
1363             return it.nextIndex() - offset;
1364         }
1365 
1366         public int previousIndex() {
1367             return it.previousIndex() - offset;
1368         }
1369 
1370         public void remove() {
1371             throw new UnsupportedOperationException();
1372         }
1373 
1374         public void set(E e) {
1375             throw new UnsupportedOperationException();
1376         }
1377 
1378         public void add(E e) {
1379             throw new UnsupportedOperationException();
1380         }
1381 
1382         @Override
1383         @SuppressWarnings("unchecked")
1384         public void forEachRemaining(Consumer<? super E> action) {
1385             Objects.requireNonNull(action);
1386             while (nextIndex() < size) {
1387                 action.accept(it.next());
1388             }
1389         }
1390     }
1391 
1392     // Support for resetting lock while deserializing
1393     private void resetLock() {
1394         UNSAFE.putObjectVolatile(this, lockOffset, new ReentrantLock());
1395     }
1396     private static final sun.misc.Unsafe UNSAFE;
1397     private static final long lockOffset;
1398     static {
1399         try {
1400             UNSAFE = sun.misc.Unsafe.getUnsafe();
1401             Class<?> k = CopyOnWriteArrayList.class;
1402             lockOffset = UNSAFE.objectFieldOffset
1403                 (k.getDeclaredField("lock"));
1404         } catch (Exception e) {
1405             throw new Error(e);
1406         }
1407     }
1408