--- jsr166/src/jsr166e/extra/ReadMostlyVector.java 2011/07/16 16:05:32 1.5 +++ jsr166/src/jsr166e/extra/ReadMostlyVector.java 2011/07/19 12:16:06 1.10 @@ -161,7 +161,7 @@ public class ReadMostlyVector impleme Object e = items[i]; if (lock.getSequence() != seq) break; - if (x == null? e == null : x.equals(e)) + if ((x == null) ? e == null : x.equals(e)) return i; } return -1; @@ -171,7 +171,7 @@ public class ReadMostlyVector impleme Object[] items = array; for (int i = index; i < fence; ++i) { Object e = items[i]; - if (x == null? e == null : x.equals(e)) + if ((x == null) ? e == null : x.equals(e)) return i; } return -1; @@ -183,7 +183,7 @@ public class ReadMostlyVector impleme Object e = items[i]; if (lock.getSequence() != seq) break; - if (x == null? e == null : x.equals(e)) + if ((x == null) ? e == null : x.equals(e)) return i; } return -1; @@ -193,7 +193,7 @@ public class ReadMostlyVector impleme Object[] items = array; for (int i = index; i >= origin; --i) { Object e = items[i]; - if (x == null? e == null : x.equals(e)) + if ((x == null) ? e == null : x.equals(e)) return i; } return -1; @@ -335,7 +335,7 @@ public class ReadMostlyVector impleme else { contained = true; for (Object e : c) { - int idx = (locked? + int idx = (locked ? rawIndexOf(e, origin, fence) : validatedIndexOf(e, items, origin, fence, seq)); @@ -659,30 +659,26 @@ public class ReadMostlyVector impleme public int indexOf(Object o) { SequenceLock lock = this.lock; - long seq = lock.awaitAvailability(); - Object[] items = array; - int n = count; - if (n <= items.length) { - boolean valid = true; - for (int i = 0; i < n; ++i) { - Object e = items[i]; - if (lock.getSequence() == seq) { - if (o == null? e == null : o.equals(e)) + for (;;) { + long seq = lock.awaitAvailability(); + Object[] items = array; + int n = count; + if (n <= items.length) { + for (int i = 0; i < n; ++i) { + Object e = items[i]; + if (lock.getSequence() != seq) { + lock.lock(); + try { + return rawIndexOf(o, 0, count); + } finally { + lock.unlock(); + } + } + else if ((o == null) ? e == null : o.equals(e)) return i; } - else { - valid = false; - break; - } - } - if (valid) return -1; - } - lock.lock(); - try { - return rawIndexOf(o, 0, count); - } finally { - lock.unlock(); + } } } @@ -692,33 +688,40 @@ public class ReadMostlyVector impleme } public Iterator iterator() { - return new Itr(this, 0); + return new Itr(this, 0); } public int lastIndexOf(Object o) { SequenceLock lock = this.lock; - long seq = lock.awaitAvailability(); - Object[] items = array; - int n = count; - if (n <= items.length) { - int idx = validatedLastIndexOf(o, items, n - 1, 0, seq); - if (lock.getSequence() == seq) - return idx; - } - lock.lock(); - try { - return rawLastIndexOf(o, count - 1, 0); - } finally { - lock.unlock(); + for (;;) { + long seq = lock.awaitAvailability(); + Object[] items = array; + int n = count; + if (n <= items.length) { + for (int i = n - 1; i >= 0; --i) { + Object e = items[i]; + if (lock.getSequence() != seq) { + lock.lock(); + try { + return rawLastIndexOf(o, 0, count); + } finally { + lock.unlock(); + } + } + else if ((o == null) ? e == null : o.equals(e)) + return i; + } + return -1; + } } } public ListIterator listIterator() { - return new Itr(this, 0); + return new Itr(this, 0); } public ListIterator listIterator(int index) { - return new Itr(this, index); + return new Itr(this, index); } public E remove(int index) { @@ -781,7 +784,7 @@ public class ReadMostlyVector impleme int ssize = toIndex - fromIndex; if (fromIndex < 0 || toIndex > c || ssize < 0) throw new IndexOutOfBoundsException(); - return new ReadMostlyVectorSublist(this, fromIndex, ssize); + return new ReadMostlyVectorSublist(this, fromIndex, ssize); } public Object[] toArray() { @@ -802,7 +805,7 @@ public class ReadMostlyVector impleme * Append the element if not present. * * @param e element to be added to this list, if absent - * @return true if the element was added + * @return {@code true} if the element was added */ public boolean addIfAbsent(E e) { boolean added; @@ -857,7 +860,7 @@ public class ReadMostlyVector impleme * Returns an iterator operating over a snapshot copy of the * elements of this collection created upon construction of the * iterator. The iterator does NOT support the - * remove method. + * {@code remove} method. * * @return an iterator over the elements in this list in proper sequence */ @@ -1057,7 +1060,7 @@ public class ReadMostlyVector impleme /** See {@link Vector#elements} */ public Enumeration elements() { - return new Itr(this, 0); + return new Itr(this, 0); } /** See {@link Vector#capacity} */ @@ -1103,7 +1106,7 @@ public class ReadMostlyVector impleme // other methods - public Object clone() { + public ReadMostlyVector clone() { SequenceLock lock = this.lock; Object[] a = null; boolean retry = false; @@ -1123,7 +1126,7 @@ public class ReadMostlyVector impleme lock.unlock(); } } - return new ReadMostlyVector(a, n, capacityIncrement); + return new ReadMostlyVector(a, n, capacityIncrement); } private void writeObject(java.io.ObjectOutputStream s) @@ -1413,7 +1416,7 @@ public class ReadMostlyVector impleme } public Iterator iterator() { - return new SubItr(this, offset); + return new SubItr(this, offset); } public int lastIndexOf(Object o) { @@ -1437,11 +1440,11 @@ public class ReadMostlyVector impleme } public ListIterator listIterator() { - return new SubItr(this, offset); + return new SubItr(this, offset); } public ListIterator listIterator(int index) { - return new SubItr(this, index + offset); + return new SubItr(this, index + offset); } public E remove(int index) { @@ -1501,7 +1504,7 @@ public class ReadMostlyVector impleme int ssize = toIndex - fromIndex; if (fromIndex < 0 || toIndex > c || ssize < 0) throw new IndexOutOfBoundsException(); - return new ReadMostlyVectorSublist(list, offset+fromIndex, ssize); + return new ReadMostlyVectorSublist(list, offset+fromIndex, ssize); } public Object[] toArray() {