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.17 by jsr166, Sat Dec 31 05:38:24 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;
653 <            Object e; boolean ex;
654 <            if (index < 0 || index >= n) {
655 <                e = null;
654 <                ex = true;
655 <            }
656 <            else {
657 <                e = items[index];
658 <                ex = false;
659 <            }
653 >            boolean outOfBounds = (index < 0 || index >= n);
654 >            @SuppressWarnings("unchecked")
655 >            E e = outOfBounds ? null : (E) items[index];
656              if (lock.getSequence() == seq) {
657 <                if (ex)
657 >                if (outOfBounds)
658                      throw new ArrayIndexOutOfBoundsException(index);
659                  else
660 <                    return (E)e;
660 >                    return e;
661              }
662          }
663      }
# Line 671 | Line 667 | public class ReadMostlyVector<E> impleme
667      }
668  
669      public int indexOf(Object o) {
670 <        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 <        }
670 >        return indexOf(o, 0);
671      }
672  
673      public boolean isEmpty() {
# Line 704 | Line 679 | public class ReadMostlyVector<E> impleme
679      }
680  
681      public int lastIndexOf(Object o) {
682 <        SequenceLock lock = this.lock;
682 >        final SequenceLock lock = this.lock;
683          for (;;) {
684              long seq = lock.awaitAvailability();
685              Object[] items = array;
# Line 737 | Line 712 | public class ReadMostlyVector<E> impleme
712      }
713  
714      public E remove(int index) {
715 <        SequenceLock lock = this.lock;
741 <        Object oldValue;
715 >        final SequenceLock lock = this.lock;
716          lock.lock();
717          try {
718              if (index < 0 || index >= count)
719                  throw new ArrayIndexOutOfBoundsException(index);
720 <            oldValue = array[index];
720 >            @SuppressWarnings("unchecked")
721 >            E oldValue = (E) array[index];
722              rawRemoveAt(index);
723 +            return oldValue;
724          } finally {
725              lock.unlock();
726          }
751        return (E)oldValue;
727      }
728  
729      public boolean remove(Object o) {
730 <        SequenceLock lock = this.lock;
756 <        boolean removed;
730 >        final SequenceLock lock = this.lock;
731          lock.lock();
732          try {
733 <            removed = rawRemoveAt(rawIndexOf(o, 0, count));
733 >            return rawRemoveAt(rawIndexOf(o, 0, count));
734          } finally {
735              lock.unlock();
736          }
763        return removed;
737      }
738  
739      public boolean removeAll(Collection<?> c) {
# Line 772 | Line 745 | public class ReadMostlyVector<E> impleme
745      }
746  
747      public E set(int index, E element) {
748 <        Object oldValue;
776 <        SequenceLock lock = this.lock;
748 >        final SequenceLock lock = this.lock;
749          lock.lock();
750          try {
751              Object[] items = array;
752              if (index < 0 || index >= count)
753                  throw new ArrayIndexOutOfBoundsException(index);
754 <            oldValue = items[index];
754 >            @SuppressWarnings("unchecked")
755 >            E oldValue = (E) items[index];
756              items[index] = element;
757 +            return oldValue;
758          } finally {
759              lock.unlock();
760          }
787        return (E)oldValue;
761      }
762  
763      public int size() {
# Line 820 | Line 793 | public class ReadMostlyVector<E> impleme
793       * @return {@code true} if the element was added
794       */
795      public boolean addIfAbsent(E e) {
796 <        boolean added;
824 <        SequenceLock lock = this.lock;
796 >        final SequenceLock lock = this.lock;
797          lock.lock();
798          try {
799              if (rawIndexOf(e, 0, count) < 0) {
800                  rawAdd(e);
801 <                added = true;
801 >                return true;
802              }
803              else
804 <                added = false;
804 >                return false;
805          } finally {
806              lock.unlock();
807          }
836        return added;
808      }
809  
810      /**
# Line 855 | Line 826 | public class ReadMostlyVector<E> impleme
826              lock.lock();
827              try {
828                  for (int i = 0; i < clen; ++i) {
829 <                    Object e = cs[i];
829 >                    @SuppressWarnings("unchecked")
830 >                    E e = (E) cs[i];
831                      if (rawIndexOf(e, 0, count) < 0) {
832                          rawAdd(e);
833                          ++added;
# Line 881 | Line 853 | public class ReadMostlyVector<E> impleme
853      }
854  
855      static final class SnapshotIterator<E> implements Iterator<E> {
856 <        final Object[] items;
857 <        int cursor;
856 >        private final Object[] items;
857 >        private int cursor;
858          SnapshotIterator(ReadMostlyVector<E> v) { items = v.toArray(); }
859          public boolean hasNext() { return cursor < items.length; }
860 +        @SuppressWarnings("unchecked")
861          public E next() {
862              if (cursor < items.length)
863                  return (E) items[cursor++];
# Line 897 | Line 870 | public class ReadMostlyVector<E> impleme
870  
871      /** See {@link Vector#firstElement} */
872      public E firstElement() {
873 <        SequenceLock lock = this.lock;
873 >        final SequenceLock lock = this.lock;
874          for (;;) {
875              long seq = lock.awaitAvailability();
876              Object[] items = array;
# Line 905 | Line 878 | public class ReadMostlyVector<E> impleme
878              int n = count;
879              if (n > len)
880                  continue;
881 <            Object e; boolean ex;
882 <            if (n > 0) {
883 <                e = items[0];
911 <                ex = false;
912 <            }
913 <            else {
914 <                e = null;
915 <                ex = true;
916 <            }
881 >            boolean empty = (n == 0);
882 >            @SuppressWarnings("unchecked")
883 >            E e = empty ? null : (E) items[0];
884              if (lock.getSequence() == seq) {
885 <                if (ex)
885 >                if (empty)
886                      throw new NoSuchElementException();
887                  else
888 <                    return (E)e;
888 >                    return e;
889              }
890          }
891      }
892  
893      /** See {@link Vector#lastElement} */
894      public E lastElement() {
895 <        SequenceLock lock = this.lock;
895 >        final SequenceLock lock = this.lock;
896          for (;;) {
897              long seq = lock.awaitAvailability();
898              Object[] items = array;
# Line 933 | Line 900 | public class ReadMostlyVector<E> impleme
900              int n = count;
901              if (n > len)
902                  continue;
903 <            Object e; boolean ex;
904 <            if (n > 0) {
905 <                e = items[n - 1];
939 <                ex = false;
940 <            }
941 <            else {
942 <                e = null;
943 <                ex = true;
944 <            }
903 >            boolean empty = (n == 0);
904 >            @SuppressWarnings("unchecked")
905 >            E e = empty ? null : (E) items[n - 1];
906              if (lock.getSequence() == seq) {
907 <                if (ex)
907 >                if (empty)
908                      throw new NoSuchElementException();
909                  else
910 <                    return (E)e;
910 >                    return e;
911              }
912          }
913      }
914  
915      /** See {@link Vector#indexOf(Object, int)} */
916      public int indexOf(Object o, int index) {
917 <        SequenceLock lock = this.lock;
917 >        final SequenceLock lock = this.lock;
918          int idx = 0;
919          boolean ex = false;
920          long seq = lock.awaitAvailability();
# Line 972 | Line 933 | public class ReadMostlyVector<E> impleme
933                  if (index < 0)
934                      ex = true;
935                  else
936 <                    idx = rawIndexOf(o, 0, count);
936 >                    idx = rawIndexOf(o, index, count);
937              } finally {
938                  lock.unlock();
939              }
# Line 984 | Line 945 | public class ReadMostlyVector<E> impleme
945  
946      /** See {@link Vector#lastIndexOf(Object, int)} */
947      public int lastIndexOf(Object o, int index) {
948 <        SequenceLock lock = this.lock;
948 >        final SequenceLock lock = this.lock;
949          int idx = 0;
950          boolean ex = false;
951          long seq = lock.awaitAvailability();
# Line 1017 | Line 978 | public class ReadMostlyVector<E> impleme
978      public void setSize(int newSize) {
979          if (newSize < 0)
980              throw new ArrayIndexOutOfBoundsException(newSize);
981 <        SequenceLock lock = this.lock;
981 >        final SequenceLock lock = this.lock;
982          lock.lock();
983          try {
984              int n = count;
# Line 1036 | Line 997 | public class ReadMostlyVector<E> impleme
997  
998      /** See {@link Vector#copyInto} */
999      public void copyInto(Object[] anArray) {
1000 <        SequenceLock lock = this.lock;
1000 >        final SequenceLock lock = this.lock;
1001          lock.lock();
1002          try {
1003              System.arraycopy(array, 0, anArray, 0, count);
# Line 1047 | Line 1008 | public class ReadMostlyVector<E> impleme
1008  
1009      /** See {@link Vector#trimToSize} */
1010      public void trimToSize() {
1011 <        SequenceLock lock = this.lock;
1011 >        final SequenceLock lock = this.lock;
1012          lock.lock();
1013          try {
1014              Object[] items = array;
# Line 1062 | Line 1023 | public class ReadMostlyVector<E> impleme
1023      /** See {@link Vector#ensureCapacity} */
1024      public void ensureCapacity(int minCapacity) {
1025          if (minCapacity > 0) {
1026 <            SequenceLock lock = this.lock;
1026 >            final SequenceLock lock = this.lock;
1027              lock.lock();
1028              try {
1029                  if (minCapacity - array.length > 0)
# Line 1121 | Line 1082 | public class ReadMostlyVector<E> impleme
1082      // other methods
1083  
1084      public ReadMostlyVector<E> clone() {
1085 <        SequenceLock lock = this.lock;
1085 >        final SequenceLock lock = this.lock;
1086          Object[] a = null;
1087          boolean retry = false;
1088          long seq = lock.awaitAvailability();
# Line 1145 | Line 1106 | public class ReadMostlyVector<E> impleme
1106  
1107      private void writeObject(java.io.ObjectOutputStream s)
1108              throws java.io.IOException {
1109 <        SequenceLock lock = this.lock;
1109 >        final SequenceLock lock = this.lock;
1110          lock.lock();
1111          try {
1112              s.defaultWriteObject();
# Line 1154 | Line 1115 | public class ReadMostlyVector<E> impleme
1115          }
1116      }
1117  
1118 <    static final class Itr<E> implements ListIterator<E>, Enumeration<E>  {
1118 >    static final class Itr<E> implements ListIterator<E>, Enumeration<E> {
1119          final ReadMostlyVector<E> list;
1120          final SequenceLock lock;
1121          Object[] items;
1122 <        Object next, prev;
1122 >        E next, prev;
1123          long seq;
1124          int cursor;
1125          int fence;
# Line 1184 | Line 1145 | public class ReadMostlyVector<E> impleme
1145                       lock.getSequence() != seq);
1146          }
1147  
1148 +        @SuppressWarnings("unchecked")
1149          public boolean hasNext() {
1150              boolean valid;
1151              int i = cursor;
# Line 1192 | Line 1154 | public class ReadMostlyVector<E> impleme
1154                      valid = false;
1155                      break;
1156                  }
1157 <                next = items[i];
1157 >                next = (E) items[i];
1158                  if (lock.getSequence() == seq) {
1159                      valid = true;
1160                      break;
# Line 1202 | Line 1164 | public class ReadMostlyVector<E> impleme
1164              return validNext = valid;
1165          }
1166  
1167 +        @SuppressWarnings("unchecked")
1168          public boolean hasPrevious() {
1169              boolean valid;
1170              int i = cursor - 1;
# Line 1210 | Line 1173 | public class ReadMostlyVector<E> impleme
1173                      valid = false;
1174                      break;
1175                  }
1176 <                prev = items[i];
1176 >                prev = (E) items[i];
1177                  if (lock.getSequence() == seq) {
1178                      valid = true;
1179                      break;
# Line 1224 | Line 1187 | public class ReadMostlyVector<E> impleme
1187              if (validNext || hasNext()) {
1188                  validNext = false;
1189                  lastRet = cursor++;
1190 <                return (E) next;
1190 >                return next;
1191              }
1192              throw new NoSuchElementException();
1193          }
# Line 1233 | Line 1196 | public class ReadMostlyVector<E> impleme
1196              if (validPrev || hasPrevious()) {
1197                  validPrev = false;
1198                  lastRet = cursor--;
1199 <                return (E) prev;
1199 >                return prev;
1200              }
1201              throw new NoSuchElementException();
1202          }
# Line 1290 | Line 1253 | public class ReadMostlyVector<E> impleme
1253          public int previousIndex() { return cursor - 1; }
1254      }
1255  
1256 <    static final class ReadMostlyVectorSublist<E> implements List<E>, RandomAccess, java.io.Serializable {
1256 >    static final class ReadMostlyVectorSublist<E>
1257 >            implements List<E>, RandomAccess, java.io.Serializable {
1258 >        static final long serialVersionUID = 3041673470172026059L;
1259 >
1260          final ReadMostlyVector<E> list;
1261          final int offset;
1262          volatile int size;
1263  
1264 <        ReadMostlyVectorSublist(ReadMostlyVector<E> list, int offset, int size) {
1264 >        ReadMostlyVectorSublist(ReadMostlyVector<E> list,
1265 >                                int offset, int size) {
1266              this.list = list;
1267              this.offset = offset;
1268              this.size = size;
# Line 1307 | Line 1274 | public class ReadMostlyVector<E> impleme
1274          }
1275  
1276          public boolean add(E element) {
1277 <            SequenceLock lock = list.lock;
1277 >            final SequenceLock lock = list.lock;
1278              lock.lock();
1279              try {
1280                  int c = size;
# Line 1320 | Line 1287 | public class ReadMostlyVector<E> impleme
1287          }
1288  
1289          public void add(int index, E element) {
1290 <            SequenceLock lock = list.lock;
1290 >            final SequenceLock lock = list.lock;
1291              lock.lock();
1292              try {
1293                  if (index < 0 || index > size)
# Line 1334 | Line 1301 | public class ReadMostlyVector<E> impleme
1301  
1302          public boolean addAll(Collection<? extends E> c) {
1303              Object[] elements = c.toArray();
1304 <            int added;
1338 <            SequenceLock lock = list.lock;
1304 >            final SequenceLock lock = list.lock;
1305              lock.lock();
1306              try {
1307                  int s = size;
1308                  int pc = list.count;
1309                  list.rawAddAllAt(offset + s, elements);
1310 <                added = list.count - pc;
1310 >                int added = list.count - pc;
1311                  size = s + added;
1312 +                return added != 0;
1313              } finally {
1314                  lock.unlock();
1315              }
1349            return added != 0;
1316          }
1317  
1318          public boolean addAll(int index, Collection<? extends E> c) {
1319              Object[] elements = c.toArray();
1320 <            int added;
1355 <            SequenceLock lock = list.lock;
1320 >            final SequenceLock lock = list.lock;
1321              lock.lock();
1322              try {
1323                  int s = size;
# Line 1360 | Line 1325 | public class ReadMostlyVector<E> impleme
1325                      throw new ArrayIndexOutOfBoundsException(index);
1326                  int pc = list.count;
1327                  list.rawAddAllAt(index + offset, elements);
1328 <                added = list.count - pc;
1328 >                int added = list.count - pc;
1329                  size = s + added;
1330 +                return added != 0;
1331              } finally {
1332                  lock.unlock();
1333              }
1368            return added != 0;
1334          }
1335  
1336          public void clear() {
1337 <            SequenceLock lock = list.lock;
1337 >            final SequenceLock lock = list.lock;
1338              lock.lock();
1339              try {
1340                  list.internalClear(offset, offset + size);
# Line 1406 | Line 1371 | public class ReadMostlyVector<E> impleme
1371          }
1372  
1373          public int indexOf(Object o) {
1374 <            SequenceLock lock = list.lock;
1374 >            final SequenceLock lock = list.lock;
1375              long seq = lock.awaitAvailability();
1376              Object[] items = list.array;
1377              int c = list.count;
# Line 1434 | Line 1399 | public class ReadMostlyVector<E> impleme
1399          }
1400  
1401          public int lastIndexOf(Object o) {
1402 <            SequenceLock lock = list.lock;
1402 >            final SequenceLock lock = list.lock;
1403              long seq = lock.awaitAvailability();
1404              Object[] items = list.array;
1405              int c = list.count;
# Line 1462 | Line 1427 | public class ReadMostlyVector<E> impleme
1427          }
1428  
1429          public E remove(int index) {
1430 <            Object result;
1466 <            SequenceLock lock = list.lock;
1430 >            final SequenceLock lock = list.lock;
1431              lock.lock();
1432              try {
1433                  Object[] items = list.array;
1434                  int i = index + offset;
1435                  if (index < 0 || index >= size || i >= items.length)
1436                      throw new ArrayIndexOutOfBoundsException(index);
1437 <                result = items[i];
1437 >                @SuppressWarnings("unchecked")
1438 >                E result = (E) items[i];
1439                  list.rawRemoveAt(i);
1440                  size--;
1441 +                return result;
1442              } finally {
1443                  lock.unlock();
1444              }
1479            return (E)result;
1445          }
1446  
1447          public boolean remove(Object o) {
1448 <            boolean removed = false;
1484 <            SequenceLock lock = list.lock;
1448 >            final SequenceLock lock = list.lock;
1449              lock.lock();
1450              try {
1451                  if (list.rawRemoveAt(list.rawIndexOf(o, offset,
1452                                                       offset + size))) {
1489                    removed = true;
1453                      --size;
1454 +                    return true;
1455                  }
1456 +                else
1457 +                    return false;
1458              } finally {
1459                  lock.unlock();
1460              }
1495            return removed;
1461          }
1462  
1463          public boolean removeAll(Collection<?> c) {
# Line 1540 | Line 1505 | public class ReadMostlyVector<E> impleme
1505          final ReadMostlyVector<E> list;
1506          final SequenceLock lock;
1507          Object[] items;
1508 <        Object next, prev;
1508 >        E next, prev;
1509          long seq;
1510          int cursor;
1511          int fence;
# Line 1571 | Line 1536 | public class ReadMostlyVector<E> impleme
1536              } while (lock.getSequence() != seq);
1537          }
1538  
1539 +        @SuppressWarnings("unchecked")
1540          public boolean hasNext() {
1541              boolean valid;
1542              int i = cursor;
# Line 1579 | Line 1545 | public class ReadMostlyVector<E> impleme
1545                      valid = false;
1546                      break;
1547                  }
1548 <                next = items[i];
1548 >                next = (E) items[i];
1549                  if (lock.getSequence() == seq) {
1550                      valid = true;
1551                      break;
# Line 1589 | Line 1555 | public class ReadMostlyVector<E> impleme
1555              return validNext = valid;
1556          }
1557  
1558 +        @SuppressWarnings("unchecked")
1559          public boolean hasPrevious() {
1560              boolean valid;
1561              int i = cursor - 1;
# Line 1597 | Line 1564 | public class ReadMostlyVector<E> impleme
1564                      valid = false;
1565                      break;
1566                  }
1567 <                prev = items[i];
1567 >                prev = (E) items[i];
1568                  if (lock.getSequence() == seq) {
1569                      valid = true;
1570                      break;
# Line 1611 | Line 1578 | public class ReadMostlyVector<E> impleme
1578              if (validNext || hasNext()) {
1579                  validNext = false;
1580                  lastRet = cursor++;
1581 <                return (E) next;
1581 >                return next;
1582              }
1583              throw new NoSuchElementException();
1584          }
# Line 1620 | Line 1587 | public class ReadMostlyVector<E> impleme
1587              if (validPrev || hasPrevious()) {
1588                  validPrev = false;
1589                  lastRet = cursor--;
1590 <                return (E) prev;
1590 >                return prev;
1591              }
1592              throw new NoSuchElementException();
1593          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines