ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/extra/ReadMostlyVector.java
(Generate patch)

Comparing jsr166/src/jsr166e/extra/ReadMostlyVector.java (file contents):
Revision 1.12 by dl, Thu Jul 21 12:49:37 2011 UTC vs.
Revision 1.18 by jsr166, Sat Dec 31 05:50:22 2011 UTC

# Line 19 | Line 19 | import java.util.*;
19   * best-effort in the presence of concurrent modifications, and do
20   * <em>NOT</em> throw {@link ConcurrentModificationException}.  An
21   * iterator's {@code next()} method returns consecutive elements as
22 < * they appear in the underlying array upon each access. Alternatvely,
22 > * they appear in the underlying array upon each access. Alternatively,
23   * method {@link #snapshotIterator} may be used for deterministic
24   * traversals, at the expense of making a copy, and unavailability of
25   * method {@code Iterator.remove}.
# Line 32 | Line 32 | import java.util.*;
32   *
33   * @author Doug Lea
34   */
35 < public class ReadMostlyVector<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable {
35 > public class ReadMostlyVector<E>
36 >        implements List<E>, RandomAccess, Cloneable, java.io.Serializable {
37      private static final long serialVersionUID = 8673264195747942595L;
38  
39      /*
# Line 199 | Line 200 | public class ReadMostlyVector<E> impleme
200          return -1;
201      }
202  
203 <    final void rawAdd(Object e) {
203 >    final void rawAdd(E e) {
204          int n = count;
205          Object[] items = array;
206          if (n >= items.length)
# Line 208 | Line 209 | public class ReadMostlyVector<E> impleme
209          count = n + 1;
210      }
211  
212 <    final void rawAddAt(int index, Object e) {
212 >    final void rawAddAt(int index, E e) {
213          int n = count;
214          Object[] items = array;
215          if (index > n)
# Line 261 | Line 262 | public class ReadMostlyVector<E> impleme
262       * field under lock.
263       */
264      final boolean internalRemoveAll(Collection<?> c, int origin, int bound) {
265 <        SequenceLock lock = this.lock;
265 >        final SequenceLock lock = this.lock;
266          boolean removed = false;
267          lock.lock();
268          try {
# Line 280 | Line 281 | public class ReadMostlyVector<E> impleme
281      }
282  
283      final boolean internalRetainAll(Collection<?> c, int origin, int bound) {
284 <        SequenceLock lock = this.lock;
284 >        final SequenceLock lock = this.lock;
285          boolean removed = false;
286          if (c != this) {
287              lock.lock();
# Line 327 | Line 328 | public class ReadMostlyVector<E> impleme
328      }
329  
330      final boolean internalContainsAll(Collection<?> c, int origin, int bound) {
331 <        SequenceLock lock = this.lock;
331 >        final SequenceLock lock = this.lock;
332          boolean contained;
333          boolean locked = false;
334          try {
# Line 367 | Line 368 | public class ReadMostlyVector<E> impleme
368      }
369  
370      final boolean internalEquals(List<?> list, int origin, int bound) {
371 <        SequenceLock lock = this.lock;
371 >        final SequenceLock lock = this.lock;
372          boolean locked = false;
373          boolean equal;
374          try {
# Line 408 | Line 409 | public class ReadMostlyVector<E> impleme
409      }
410  
411      final int internalHashCode(int origin, int bound) {
412 <        SequenceLock lock = this.lock;
412 >        final SequenceLock lock = this.lock;
413          int hash;
414          boolean locked = false;
415          try {
# Line 440 | Line 441 | public class ReadMostlyVector<E> impleme
441      }
442  
443      final String internalToString(int origin, int bound) {
444 <        SequenceLock lock = this.lock;
444 >        final SequenceLock lock = this.lock;
445          String ret;
446          boolean locked = false;
447          try {
# Line 487 | Line 488 | public class ReadMostlyVector<E> impleme
488  
489      final Object[] internalToArray(int origin, int bound) {
490          Object[] result;
491 <        SequenceLock lock = this.lock;
491 >        final SequenceLock lock = this.lock;
492          boolean locked = false;
493          try {
494              for (;;) {
# Line 514 | Line 515 | public class ReadMostlyVector<E> impleme
515          return result;
516      }
517  
518 +    @SuppressWarnings("unchecked")
519      final <T> T[] internalToArray(T[] a, int origin, int bound) {
520          int alen = a.length;
521          T[] result;
522 <        SequenceLock lock = this.lock;
522 >        final SequenceLock lock = this.lock;
523          boolean locked = false;
524          try {
525              for (;;) {
# Line 556 | Line 558 | public class ReadMostlyVector<E> impleme
558      // public List methods
559  
560      public boolean add(E e) {
561 <        SequenceLock lock = this.lock;
561 >        final SequenceLock lock = this.lock;
562          lock.lock();
563          try {
564              rawAdd(e);
# Line 567 | Line 569 | public class ReadMostlyVector<E> impleme
569      }
570  
571      public void add(int index, E element) {
572 <        SequenceLock lock = this.lock;
572 >        final SequenceLock lock = this.lock;
573          lock.lock();
574          try {
575              rawAddAt(index, element);
# Line 581 | Line 583 | public class ReadMostlyVector<E> impleme
583          int len = elements.length;
584          if (len == 0)
585              return false;
586 <        SequenceLock lock = this.lock;
586 >        final SequenceLock lock = this.lock;
587          lock.lock();
588          try {
589              Object[] items = array;
# Line 598 | Line 600 | public class ReadMostlyVector<E> impleme
600      }
601  
602      public boolean addAll(int index, Collection<? extends E> c) {
603 <        SequenceLock lock = this.lock;
603 >        final SequenceLock lock = this.lock;
604          boolean ret;
605          Object[] elements = c.toArray();
606          lock.lock();
# Line 611 | Line 613 | public class ReadMostlyVector<E> impleme
613      }
614  
615      public void clear() {
616 <        SequenceLock lock = this.lock;
616 >        final SequenceLock lock = this.lock;
617          lock.lock();
618          try {
619              int n = count;
# Line 641 | Line 643 | public class ReadMostlyVector<E> impleme
643      }
644  
645      public E get(int index) {
646 <        SequenceLock lock = this.lock;
646 >        final SequenceLock lock = this.lock;
647          for (;;) {
648              long seq = lock.awaitAvailability();
649              int n = count;
650              Object[] items = array;
651 <            if (n > items.length)
652 <                continue;
651 <            Object e; boolean ex;
652 <            if (index < 0 || index >= n) {
653 <                e = null;
654 <                ex = true;
655 <            }
656 <            else {
657 <                e = items[index];
658 <                ex = false;
659 <            }
651 >            @SuppressWarnings("unchecked")
652 >            E e = (index < items.length) ? (E) items[index] : null;
653              if (lock.getSequence() == seq) {
654 <                if (ex)
654 >                if (index >= n)
655                      throw new ArrayIndexOutOfBoundsException(index);
656 <                else
664 <                    return (E)e;
656 >                return e;
657              }
658          }
659      }
# Line 671 | Line 663 | public class ReadMostlyVector<E> impleme
663      }
664  
665      public int indexOf(Object o) {
666 <        SequenceLock lock = this.lock;
675 <        for (;;) {
676 <            long seq = lock.awaitAvailability();
677 <            Object[] items = array;
678 <            int n = count;
679 <            if (n <= items.length) {
680 <                for (int i = 0; i < n; ++i) {
681 <                    Object e = items[i];
682 <                    if (lock.getSequence() != seq) {
683 <                        lock.lock();
684 <                        try {
685 <                            return rawIndexOf(o, 0, count);
686 <                        } finally {
687 <                            lock.unlock();
688 <                        }
689 <                    }
690 <                    else if ((o == null) ? e == null : o.equals(e))
691 <                        return i;
692 <                }
693 <                return -1;
694 <            }
695 <        }
666 >        return indexOf(o, 0);
667      }
668  
669      public boolean isEmpty() {
# Line 704 | Line 675 | public class ReadMostlyVector<E> impleme
675      }
676  
677      public int lastIndexOf(Object o) {
678 <        SequenceLock lock = this.lock;
678 >        final SequenceLock lock = this.lock;
679          for (;;) {
680              long seq = lock.awaitAvailability();
681              Object[] items = array;
# Line 737 | Line 708 | public class ReadMostlyVector<E> impleme
708      }
709  
710      public E remove(int index) {
711 <        SequenceLock lock = this.lock;
741 <        Object oldValue;
711 >        final SequenceLock lock = this.lock;
712          lock.lock();
713          try {
714              if (index < 0 || index >= count)
715                  throw new ArrayIndexOutOfBoundsException(index);
716 <            oldValue = array[index];
716 >            @SuppressWarnings("unchecked")
717 >            E oldValue = (E) array[index];
718              rawRemoveAt(index);
719 +            return oldValue;
720          } finally {
721              lock.unlock();
722          }
751        return (E)oldValue;
723      }
724  
725      public boolean remove(Object o) {
726 <        SequenceLock lock = this.lock;
756 <        boolean removed;
726 >        final SequenceLock lock = this.lock;
727          lock.lock();
728          try {
729 <            removed = rawRemoveAt(rawIndexOf(o, 0, count));
729 >            return rawRemoveAt(rawIndexOf(o, 0, count));
730          } finally {
731              lock.unlock();
732          }
763        return removed;
733      }
734  
735      public boolean removeAll(Collection<?> c) {
# Line 772 | Line 741 | public class ReadMostlyVector<E> impleme
741      }
742  
743      public E set(int index, E element) {
744 <        Object oldValue;
776 <        SequenceLock lock = this.lock;
744 >        final SequenceLock lock = this.lock;
745          lock.lock();
746          try {
747              Object[] items = array;
748              if (index < 0 || index >= count)
749                  throw new ArrayIndexOutOfBoundsException(index);
750 <            oldValue = items[index];
750 >            @SuppressWarnings("unchecked")
751 >            E oldValue = (E) items[index];
752              items[index] = element;
753 +            return oldValue;
754          } finally {
755              lock.unlock();
756          }
787        return (E)oldValue;
757      }
758  
759      public int size() {
# Line 820 | Line 789 | public class ReadMostlyVector<E> impleme
789       * @return {@code true} if the element was added
790       */
791      public boolean addIfAbsent(E e) {
792 <        boolean added;
824 <        SequenceLock lock = this.lock;
792 >        final SequenceLock lock = this.lock;
793          lock.lock();
794          try {
795              if (rawIndexOf(e, 0, count) < 0) {
796                  rawAdd(e);
797 <                added = true;
797 >                return true;
798              }
799              else
800 <                added = false;
800 >                return false;
801          } finally {
802              lock.unlock();
803          }
836        return added;
804      }
805  
806      /**
# Line 855 | Line 822 | public class ReadMostlyVector<E> impleme
822              lock.lock();
823              try {
824                  for (int i = 0; i < clen; ++i) {
825 <                    Object e = cs[i];
825 >                    @SuppressWarnings("unchecked")
826 >                    E e = (E) cs[i];
827                      if (rawIndexOf(e, 0, count) < 0) {
828                          rawAdd(e);
829                          ++added;
# Line 881 | Line 849 | public class ReadMostlyVector<E> impleme
849      }
850  
851      static final class SnapshotIterator<E> implements Iterator<E> {
852 <        final Object[] items;
853 <        int cursor;
852 >        private final Object[] items;
853 >        private int cursor;
854          SnapshotIterator(ReadMostlyVector<E> v) { items = v.toArray(); }
855          public boolean hasNext() { return cursor < items.length; }
856 +        @SuppressWarnings("unchecked")
857          public E next() {
858              if (cursor < items.length)
859                  return (E) items[cursor++];
# Line 897 | Line 866 | public class ReadMostlyVector<E> impleme
866  
867      /** See {@link Vector#firstElement} */
868      public E firstElement() {
869 <        SequenceLock lock = this.lock;
869 >        final SequenceLock lock = this.lock;
870          for (;;) {
871              long seq = lock.awaitAvailability();
872              Object[] items = array;
# Line 905 | Line 874 | public class ReadMostlyVector<E> impleme
874              int n = count;
875              if (n > len)
876                  continue;
877 <            Object e; boolean ex;
878 <            if (n > 0) {
879 <                e = items[0];
911 <                ex = false;
912 <            }
913 <            else {
914 <                e = null;
915 <                ex = true;
916 <            }
877 >            boolean empty = (n == 0);
878 >            @SuppressWarnings("unchecked")
879 >            E e = empty ? null : (E) items[0];
880              if (lock.getSequence() == seq) {
881 <                if (ex)
881 >                if (empty)
882                      throw new NoSuchElementException();
883                  else
884 <                    return (E)e;
884 >                    return e;
885              }
886          }
887      }
888  
889      /** See {@link Vector#lastElement} */
890      public E lastElement() {
891 <        SequenceLock lock = this.lock;
891 >        final SequenceLock lock = this.lock;
892          for (;;) {
893              long seq = lock.awaitAvailability();
894              Object[] items = array;
# Line 933 | Line 896 | public class ReadMostlyVector<E> impleme
896              int n = count;
897              if (n > len)
898                  continue;
899 <            Object e; boolean ex;
900 <            if (n > 0) {
901 <                e = items[n - 1];
939 <                ex = false;
940 <            }
941 <            else {
942 <                e = null;
943 <                ex = true;
944 <            }
899 >            boolean empty = (n == 0);
900 >            @SuppressWarnings("unchecked")
901 >            E e = empty ? null : (E) items[n - 1];
902              if (lock.getSequence() == seq) {
903 <                if (ex)
903 >                if (empty)
904                      throw new NoSuchElementException();
905                  else
906 <                    return (E)e;
906 >                    return e;
907              }
908          }
909      }
910  
911      /** See {@link Vector#indexOf(Object, int)} */
912      public int indexOf(Object o, int index) {
913 <        SequenceLock lock = this.lock;
913 >        final SequenceLock lock = this.lock;
914          int idx = 0;
915          boolean ex = false;
916          long seq = lock.awaitAvailability();
# Line 972 | Line 929 | public class ReadMostlyVector<E> impleme
929                  if (index < 0)
930                      ex = true;
931                  else
932 <                    idx = rawIndexOf(o, 0, count);
932 >                    idx = rawIndexOf(o, index, count);
933              } finally {
934                  lock.unlock();
935              }
# Line 984 | Line 941 | public class ReadMostlyVector<E> impleme
941  
942      /** See {@link Vector#lastIndexOf(Object, int)} */
943      public int lastIndexOf(Object o, int index) {
944 <        SequenceLock lock = this.lock;
944 >        final SequenceLock lock = this.lock;
945          int idx = 0;
946          boolean ex = false;
947          long seq = lock.awaitAvailability();
# Line 1017 | Line 974 | public class ReadMostlyVector<E> impleme
974      public void setSize(int newSize) {
975          if (newSize < 0)
976              throw new ArrayIndexOutOfBoundsException(newSize);
977 <        SequenceLock lock = this.lock;
977 >        final SequenceLock lock = this.lock;
978          lock.lock();
979          try {
980              int n = count;
# Line 1036 | Line 993 | public class ReadMostlyVector<E> impleme
993  
994      /** See {@link Vector#copyInto} */
995      public void copyInto(Object[] anArray) {
996 <        SequenceLock lock = this.lock;
996 >        final SequenceLock lock = this.lock;
997          lock.lock();
998          try {
999              System.arraycopy(array, 0, anArray, 0, count);
# Line 1047 | Line 1004 | public class ReadMostlyVector<E> impleme
1004  
1005      /** See {@link Vector#trimToSize} */
1006      public void trimToSize() {
1007 <        SequenceLock lock = this.lock;
1007 >        final SequenceLock lock = this.lock;
1008          lock.lock();
1009          try {
1010              Object[] items = array;
# Line 1062 | Line 1019 | public class ReadMostlyVector<E> impleme
1019      /** See {@link Vector#ensureCapacity} */
1020      public void ensureCapacity(int minCapacity) {
1021          if (minCapacity > 0) {
1022 <            SequenceLock lock = this.lock;
1022 >            final SequenceLock lock = this.lock;
1023              lock.lock();
1024              try {
1025                  if (minCapacity - array.length > 0)
# Line 1121 | Line 1078 | public class ReadMostlyVector<E> impleme
1078      // other methods
1079  
1080      public ReadMostlyVector<E> clone() {
1081 <        SequenceLock lock = this.lock;
1081 >        final SequenceLock lock = this.lock;
1082          Object[] a = null;
1083          boolean retry = false;
1084          long seq = lock.awaitAvailability();
# Line 1145 | Line 1102 | public class ReadMostlyVector<E> impleme
1102  
1103      private void writeObject(java.io.ObjectOutputStream s)
1104              throws java.io.IOException {
1105 <        SequenceLock lock = this.lock;
1105 >        final SequenceLock lock = this.lock;
1106          lock.lock();
1107          try {
1108              s.defaultWriteObject();
# Line 1154 | Line 1111 | public class ReadMostlyVector<E> impleme
1111          }
1112      }
1113  
1114 <    static final class Itr<E> implements ListIterator<E>, Enumeration<E>  {
1114 >    static final class Itr<E> implements ListIterator<E>, Enumeration<E> {
1115          final ReadMostlyVector<E> list;
1116          final SequenceLock lock;
1117          Object[] items;
1118 <        Object next, prev;
1118 >        E next, prev;
1119          long seq;
1120          int cursor;
1121          int fence;
# Line 1184 | Line 1141 | public class ReadMostlyVector<E> impleme
1141                       lock.getSequence() != seq);
1142          }
1143  
1144 +        @SuppressWarnings("unchecked")
1145          public boolean hasNext() {
1146              boolean valid;
1147              int i = cursor;
# Line 1192 | Line 1150 | public class ReadMostlyVector<E> impleme
1150                      valid = false;
1151                      break;
1152                  }
1153 <                next = items[i];
1153 >                next = (E) items[i];
1154                  if (lock.getSequence() == seq) {
1155                      valid = true;
1156                      break;
# Line 1202 | Line 1160 | public class ReadMostlyVector<E> impleme
1160              return validNext = valid;
1161          }
1162  
1163 +        @SuppressWarnings("unchecked")
1164          public boolean hasPrevious() {
1165              boolean valid;
1166              int i = cursor - 1;
# Line 1210 | Line 1169 | public class ReadMostlyVector<E> impleme
1169                      valid = false;
1170                      break;
1171                  }
1172 <                prev = items[i];
1172 >                prev = (E) items[i];
1173                  if (lock.getSequence() == seq) {
1174                      valid = true;
1175                      break;
# Line 1224 | Line 1183 | public class ReadMostlyVector<E> impleme
1183              if (validNext || hasNext()) {
1184                  validNext = false;
1185                  lastRet = cursor++;
1186 <                return (E) next;
1186 >                return next;
1187              }
1188              throw new NoSuchElementException();
1189          }
# Line 1233 | Line 1192 | public class ReadMostlyVector<E> impleme
1192              if (validPrev || hasPrevious()) {
1193                  validPrev = false;
1194                  lastRet = cursor--;
1195 <                return (E) prev;
1195 >                return prev;
1196              }
1197              throw new NoSuchElementException();
1198          }
# Line 1290 | Line 1249 | public class ReadMostlyVector<E> impleme
1249          public int previousIndex() { return cursor - 1; }
1250      }
1251  
1252 <    static final class ReadMostlyVectorSublist<E> implements List<E>, RandomAccess, java.io.Serializable {
1252 >    static final class ReadMostlyVectorSublist<E>
1253 >            implements List<E>, RandomAccess, java.io.Serializable {
1254 >        static final long serialVersionUID = 3041673470172026059L;
1255 >
1256          final ReadMostlyVector<E> list;
1257          final int offset;
1258          volatile int size;
1259  
1260 <        ReadMostlyVectorSublist(ReadMostlyVector<E> list, int offset, int size) {
1260 >        ReadMostlyVectorSublist(ReadMostlyVector<E> list,
1261 >                                int offset, int size) {
1262              this.list = list;
1263              this.offset = offset;
1264              this.size = size;
# Line 1307 | Line 1270 | public class ReadMostlyVector<E> impleme
1270          }
1271  
1272          public boolean add(E element) {
1273 <            SequenceLock lock = list.lock;
1273 >            final SequenceLock lock = list.lock;
1274              lock.lock();
1275              try {
1276                  int c = size;
# Line 1320 | Line 1283 | public class ReadMostlyVector<E> impleme
1283          }
1284  
1285          public void add(int index, E element) {
1286 <            SequenceLock lock = list.lock;
1286 >            final SequenceLock lock = list.lock;
1287              lock.lock();
1288              try {
1289                  if (index < 0 || index > size)
# Line 1334 | Line 1297 | public class ReadMostlyVector<E> impleme
1297  
1298          public boolean addAll(Collection<? extends E> c) {
1299              Object[] elements = c.toArray();
1300 <            int added;
1338 <            SequenceLock lock = list.lock;
1300 >            final SequenceLock lock = list.lock;
1301              lock.lock();
1302              try {
1303                  int s = size;
1304                  int pc = list.count;
1305                  list.rawAddAllAt(offset + s, elements);
1306 <                added = list.count - pc;
1306 >                int added = list.count - pc;
1307                  size = s + added;
1308 +                return added != 0;
1309              } finally {
1310                  lock.unlock();
1311              }
1349            return added != 0;
1312          }
1313  
1314          public boolean addAll(int index, Collection<? extends E> c) {
1315              Object[] elements = c.toArray();
1316 <            int added;
1355 <            SequenceLock lock = list.lock;
1316 >            final SequenceLock lock = list.lock;
1317              lock.lock();
1318              try {
1319                  int s = size;
# Line 1360 | Line 1321 | public class ReadMostlyVector<E> impleme
1321                      throw new ArrayIndexOutOfBoundsException(index);
1322                  int pc = list.count;
1323                  list.rawAddAllAt(index + offset, elements);
1324 <                added = list.count - pc;
1324 >                int added = list.count - pc;
1325                  size = s + added;
1326 +                return added != 0;
1327              } finally {
1328                  lock.unlock();
1329              }
1368            return added != 0;
1330          }
1331  
1332          public void clear() {
1333 <            SequenceLock lock = list.lock;
1333 >            final SequenceLock lock = list.lock;
1334              lock.lock();
1335              try {
1336                  list.internalClear(offset, offset + size);
# Line 1406 | Line 1367 | public class ReadMostlyVector<E> impleme
1367          }
1368  
1369          public int indexOf(Object o) {
1370 <            SequenceLock lock = list.lock;
1370 >            final SequenceLock lock = list.lock;
1371              long seq = lock.awaitAvailability();
1372              Object[] items = list.array;
1373              int c = list.count;
# Line 1434 | Line 1395 | public class ReadMostlyVector<E> impleme
1395          }
1396  
1397          public int lastIndexOf(Object o) {
1398 <            SequenceLock lock = list.lock;
1398 >            final SequenceLock lock = list.lock;
1399              long seq = lock.awaitAvailability();
1400              Object[] items = list.array;
1401              int c = list.count;
# Line 1462 | Line 1423 | public class ReadMostlyVector<E> impleme
1423          }
1424  
1425          public E remove(int index) {
1426 <            Object result;
1466 <            SequenceLock lock = list.lock;
1426 >            final SequenceLock lock = list.lock;
1427              lock.lock();
1428              try {
1429                  Object[] items = list.array;
1430                  int i = index + offset;
1431                  if (index < 0 || index >= size || i >= items.length)
1432                      throw new ArrayIndexOutOfBoundsException(index);
1433 <                result = items[i];
1433 >                @SuppressWarnings("unchecked")
1434 >                E result = (E) items[i];
1435                  list.rawRemoveAt(i);
1436                  size--;
1437 +                return result;
1438              } finally {
1439                  lock.unlock();
1440              }
1479            return (E)result;
1441          }
1442  
1443          public boolean remove(Object o) {
1444 <            boolean removed = false;
1484 <            SequenceLock lock = list.lock;
1444 >            final SequenceLock lock = list.lock;
1445              lock.lock();
1446              try {
1447                  if (list.rawRemoveAt(list.rawIndexOf(o, offset,
1448                                                       offset + size))) {
1489                    removed = true;
1449                      --size;
1450 +                    return true;
1451                  }
1452 +                else
1453 +                    return false;
1454              } finally {
1455                  lock.unlock();
1456              }
1495            return removed;
1457          }
1458  
1459          public boolean removeAll(Collection<?> c) {
# Line 1540 | Line 1501 | public class ReadMostlyVector<E> impleme
1501          final ReadMostlyVector<E> list;
1502          final SequenceLock lock;
1503          Object[] items;
1504 <        Object next, prev;
1504 >        E next, prev;
1505          long seq;
1506          int cursor;
1507          int fence;
# Line 1571 | Line 1532 | public class ReadMostlyVector<E> impleme
1532              } while (lock.getSequence() != seq);
1533          }
1534  
1535 +        @SuppressWarnings("unchecked")
1536          public boolean hasNext() {
1537              boolean valid;
1538              int i = cursor;
# Line 1579 | Line 1541 | public class ReadMostlyVector<E> impleme
1541                      valid = false;
1542                      break;
1543                  }
1544 <                next = items[i];
1544 >                next = (E) items[i];
1545                  if (lock.getSequence() == seq) {
1546                      valid = true;
1547                      break;
# Line 1589 | Line 1551 | public class ReadMostlyVector<E> impleme
1551              return validNext = valid;
1552          }
1553  
1554 +        @SuppressWarnings("unchecked")
1555          public boolean hasPrevious() {
1556              boolean valid;
1557              int i = cursor - 1;
# Line 1597 | Line 1560 | public class ReadMostlyVector<E> impleme
1560                      valid = false;
1561                      break;
1562                  }
1563 <                prev = items[i];
1563 >                prev = (E) items[i];
1564                  if (lock.getSequence() == seq) {
1565                      valid = true;
1566                      break;
# Line 1611 | Line 1574 | public class ReadMostlyVector<E> impleme
1574              if (validNext || hasNext()) {
1575                  validNext = false;
1576                  lastRet = cursor++;
1577 <                return (E) next;
1577 >                return next;
1578              }
1579              throw new NoSuchElementException();
1580          }
# Line 1620 | Line 1583 | public class ReadMostlyVector<E> impleme
1583              if (validPrev || hasPrevious()) {
1584                  validPrev = false;
1585                  lastRet = cursor--;
1586 <                return (E) prev;
1586 >                return prev;
1587              }
1588              throw new NoSuchElementException();
1589          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines