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.4 by dl, Sat Jul 16 15:05:04 2011 UTC vs.
Revision 1.6 by jsr166, Sun Jul 17 17:17:46 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.
22 > * they appear in the underlying array upon each access. Alternatvely,
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}.
26   *
27   * <p>Otherwise, this class supports all methods, under the same
28   * documented specifications, as {@code Vector}.  Consult {@link
# Line 158 | 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 168 | 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 180 | 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 190 | 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 332 | 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 664 | Line 667 | public class ReadMostlyVector<E> impleme
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))
670 >                    if ((o == null) ? e == null : o.equals(e))
671                          return i;
672                  }
673                  else {
# Line 850 | Line 853 | public class ReadMostlyVector<E> impleme
853          return added;
854      }
855  
856 +    /**
857 +     * Returns an iterator operating over a snapshot copy of the
858 +     * elements of this collection created upon construction of the
859 +     * iterator. The iterator does <em>NOT</em> support the
860 +     * <tt>remove</tt> method.
861 +     *
862 +     * @return an iterator over the elements in this list in proper sequence
863 +     */
864 +    public Iterator<E> snapshotIterator() {
865 +        return new SnapshotIterator<E>(this);
866 +    }
867 +
868 +    static final class SnapshotIterator<E> implements Iterator<E> {
869 +        final Object[] items;
870 +        int cursor;
871 +        SnapshotIterator(ReadMostlyVector<E> v) { items = v.toArray(); }
872 +        public boolean hasNext() { return cursor < items.length; }
873 +        public E next() {
874 +            if (cursor < items.length)
875 +                return (E) items[cursor++];
876 +            throw new NoSuchElementException();
877 +        }
878 +        public void remove() { throw new UnsupportedOperationException() ; }
879 +    }
880 +
881      // Vector-only methods
882  
883      /** See {@link Vector#firstElement} */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines