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.5 by dl, Sat Jul 16 16:05:32 2011 UTC vs.
Revision 1.10 by jsr166, Tue Jul 19 12:16:06 2011 UTC

# Line 161 | Line 161 | public class ReadMostlyVector<E> impleme
161              Object e = items[i];
162              if (lock.getSequence() != seq)
163                  break;
164 <            if (x == null? e == null : x.equals(e))
164 >            if ((x == null) ? e == null : x.equals(e))
165                  return i;
166          }
167          return -1;
# Line 171 | Line 171 | public class ReadMostlyVector<E> impleme
171          Object[] items = array;
172          for (int i = index; i < fence; ++i) {
173              Object e = items[i];
174 <            if (x == null? e == null : x.equals(e))
174 >            if ((x == null) ? e == null : x.equals(e))
175                  return i;
176          }
177          return -1;
# Line 183 | Line 183 | public class ReadMostlyVector<E> impleme
183              Object e = items[i];
184              if (lock.getSequence() != seq)
185                  break;
186 <            if (x == null? e == null : x.equals(e))
186 >            if ((x == null) ? e == null : x.equals(e))
187                  return i;
188          }
189          return -1;
# Line 193 | Line 193 | public class ReadMostlyVector<E> impleme
193          Object[] items = array;
194          for (int i = index; i >= origin; --i) {
195              Object e = items[i];
196 <            if (x == null? e == null : x.equals(e))
196 >            if ((x == null) ? e == null : x.equals(e))
197                  return i;
198          }
199          return -1;
# Line 335 | Line 335 | public class ReadMostlyVector<E> impleme
335                  else {
336                      contained = true;
337                      for (Object e : c) {
338 <                        int idx = (locked?
338 >                        int idx = (locked ?
339                                     rawIndexOf(e, origin, fence) :
340                                     validatedIndexOf(e, items, origin,
341                                                      fence, seq));
# Line 659 | Line 659 | public class ReadMostlyVector<E> impleme
659  
660      public int indexOf(Object o) {
661          SequenceLock lock = this.lock;
662 <        long seq = lock.awaitAvailability();
663 <        Object[] items = array;
664 <        int n = count;
665 <        if (n <= items.length) {
666 <            boolean valid = true;
667 <            for (int i = 0; i < n; ++i) {
668 <                Object e = items[i];
669 <                if (lock.getSequence() == seq) {
670 <                    if (o == null? e == null : o.equals(e))
662 >        for (;;) {
663 >            long seq = lock.awaitAvailability();
664 >            Object[] items = array;
665 >            int n = count;
666 >            if (n <= items.length) {
667 >                for (int i = 0; i < n; ++i) {
668 >                    Object e = items[i];
669 >                    if (lock.getSequence() != seq) {
670 >                        lock.lock();
671 >                        try {
672 >                            return rawIndexOf(o, 0, count);
673 >                        } finally {
674 >                            lock.unlock();
675 >                        }
676 >                    }
677 >                    else if ((o == null) ? e == null : o.equals(e))
678                          return i;
679                  }
673                else {
674                    valid = false;
675                    break;
676                }
677            }
678            if (valid)
680                  return -1;
681 <        }
681 <        lock.lock();
682 <        try {
683 <            return rawIndexOf(o, 0, count);
684 <        } finally {
685 <            lock.unlock();
681 >            }
682          }
683      }
684  
# Line 692 | Line 688 | public class ReadMostlyVector<E> impleme
688      }
689  
690      public Iterator<E> iterator() {
691 <        return new Itr(this, 0);
691 >        return new Itr<E>(this, 0);
692      }
693  
694      public int lastIndexOf(Object o) {
695          SequenceLock lock = this.lock;
696 <        long seq = lock.awaitAvailability();
697 <        Object[] items = array;
698 <        int n = count;
699 <        if (n <= items.length) {
700 <            int idx = validatedLastIndexOf(o, items, n - 1, 0, seq);
701 <            if (lock.getSequence() == seq)
702 <                return idx;
703 <        }
704 <        lock.lock();
705 <        try {
706 <            return rawLastIndexOf(o, count - 1, 0);
707 <        } finally {
708 <            lock.unlock();
696 >        for (;;) {
697 >            long seq = lock.awaitAvailability();
698 >            Object[] items = array;
699 >            int n = count;
700 >            if (n <= items.length) {
701 >                for (int i = n - 1; i >= 0; --i) {
702 >                    Object e = items[i];
703 >                    if (lock.getSequence() != seq) {
704 >                        lock.lock();
705 >                        try {
706 >                            return rawLastIndexOf(o, 0, count);
707 >                        } finally {
708 >                            lock.unlock();
709 >                        }
710 >                    }
711 >                    else if ((o == null) ? e == null : o.equals(e))
712 >                        return i;
713 >                }
714 >                return -1;
715 >            }
716          }
717      }
718  
719      public ListIterator<E> listIterator() {
720 <        return new Itr(this, 0);
720 >        return new Itr<E>(this, 0);
721      }
722  
723      public ListIterator<E> listIterator(int index) {
724 <        return new Itr(this, index);
724 >        return new Itr<E>(this, index);
725      }
726  
727      public E remove(int index) {
# Line 781 | Line 784 | public class ReadMostlyVector<E> impleme
784          int ssize = toIndex - fromIndex;
785          if (fromIndex < 0 || toIndex > c || ssize < 0)
786              throw new IndexOutOfBoundsException();
787 <        return new ReadMostlyVectorSublist(this, fromIndex, ssize);
787 >        return new ReadMostlyVectorSublist<E>(this, fromIndex, ssize);
788      }
789  
790      public Object[] toArray() {
# Line 802 | Line 805 | public class ReadMostlyVector<E> impleme
805       * Append the element if not present.
806       *
807       * @param e element to be added to this list, if absent
808 <     * @return <tt>true</tt> if the element was added
808 >     * @return {@code true} if the element was added
809       */
810      public boolean addIfAbsent(E e) {
811          boolean added;
# Line 857 | Line 860 | public class ReadMostlyVector<E> impleme
860       * Returns an iterator operating over a snapshot copy of the
861       * elements of this collection created upon construction of the
862       * iterator. The iterator does <em>NOT</em> support the
863 <     * <tt>remove</tt> method.
863 >     * {@code remove} method.
864       *
865       * @return an iterator over the elements in this list in proper sequence
866       */
# Line 1057 | Line 1060 | public class ReadMostlyVector<E> impleme
1060  
1061      /** See {@link Vector#elements} */
1062      public Enumeration<E> elements() {
1063 <        return new Itr(this, 0);
1063 >        return new Itr<E>(this, 0);
1064      }
1065  
1066      /** See {@link Vector#capacity} */
# Line 1103 | Line 1106 | public class ReadMostlyVector<E> impleme
1106  
1107      // other methods
1108  
1109 <    public Object clone() {
1109 >    public ReadMostlyVector<E> clone() {
1110          SequenceLock lock = this.lock;
1111          Object[] a = null;
1112          boolean retry = false;
# Line 1123 | Line 1126 | public class ReadMostlyVector<E> impleme
1126                  lock.unlock();
1127              }
1128          }
1129 <        return new ReadMostlyVector(a, n, capacityIncrement);
1129 >        return new ReadMostlyVector<E>(a, n, capacityIncrement);
1130      }
1131  
1132      private void writeObject(java.io.ObjectOutputStream s)
# Line 1413 | Line 1416 | public class ReadMostlyVector<E> impleme
1416          }
1417  
1418          public Iterator<E> iterator() {
1419 <            return new SubItr(this, offset);
1419 >            return new SubItr<E>(this, offset);
1420          }
1421  
1422          public int lastIndexOf(Object o) {
# Line 1437 | Line 1440 | public class ReadMostlyVector<E> impleme
1440          }
1441  
1442          public ListIterator<E> listIterator() {
1443 <            return new SubItr(this, offset);
1443 >            return new SubItr<E>(this, offset);
1444          }
1445  
1446          public ListIterator<E> listIterator(int index) {
1447 <            return new SubItr(this, index + offset);
1447 >            return new SubItr<E>(this, index + offset);
1448          }
1449  
1450          public E remove(int index) {
# Line 1501 | Line 1504 | public class ReadMostlyVector<E> impleme
1504              int ssize = toIndex - fromIndex;
1505              if (fromIndex < 0 || toIndex > c || ssize < 0)
1506                  throw new IndexOutOfBoundsException();
1507 <            return new ReadMostlyVectorSublist(list, offset+fromIndex, ssize);
1507 >            return new ReadMostlyVectorSublist<E>(list, offset+fromIndex, ssize);
1508          }
1509  
1510          public Object[] toArray() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines