14 |
|
* throughput when invocations of read-only methods by multiple |
15 |
|
* threads are most common. |
16 |
|
* |
17 |
< |
* <p> The iterators returned by this class's {@link #iterator() |
17 |
> |
* <p>The iterators returned by this class's {@link #iterator() |
18 |
|
* iterator} and {@link #listIterator(int) listIterator} methods are |
19 |
|
* best-effort in the presence of concurrent modifications, and do |
20 |
|
* <em>NOT</em> throw {@link ConcurrentModificationException}. An |
93 |
|
* Creates an empty vector with the given initial capacity. |
94 |
|
* |
95 |
|
* @param initialCapacity the initial capacity of the underlying array |
96 |
– |
* |
96 |
|
* @throws IllegalArgumentException if initial capacity is negative |
97 |
|
*/ |
98 |
|
public ReadMostlyVector(int initialCapacity) { |
157 |
|
else |
158 |
|
newCapacity = MAX_ARRAY_SIZE; |
159 |
|
} |
160 |
< |
return array = ((items == null) ? |
160 |
> |
return array = ((items == null) ? |
161 |
|
new Object[newCapacity] : |
162 |
|
Arrays.copyOf(items, newCapacity)); |
163 |
|
} |
171 |
|
static int findFirstIndex(Object[] items, Object x, int index, int fence) { |
172 |
|
int len; |
173 |
|
if (items != null && (len = items.length) > 0) { |
174 |
< |
int start = (index < 0)? 0 : index; |
174 |
> |
int start = (index < 0) ? 0 : index; |
175 |
|
int bound = (fence < len) ? fence : len; |
176 |
|
for (int i = start; i < bound; ++i) { |
177 |
|
Object e = items[i]; |
405 |
|
sb.append('['); |
406 |
|
for (;;) { |
407 |
|
Object e = items[i]; |
408 |
< |
sb.append((e == this)? "(this Collection)" : e.toString()); |
408 |
> |
sb.append((e == this) ? "(this Collection)" : e.toString()); |
409 |
|
if (++i < fence) |
410 |
|
sb.append(',').append(' '); |
411 |
|
else |
426 |
|
n = len; |
427 |
|
int fence = bound < 0 || bound > n ? n : bound; |
428 |
|
int i = (origin < 0) ? 0 : origin; |
429 |
< |
if (i != fence) |
429 |
> |
if (i != fence) |
430 |
|
return Arrays.copyOfRange(items, i, fence, Object[].class); |
431 |
|
} |
432 |
|
return new Object[0]; |
567 |
|
final StampedLock lock = this.lock; |
568 |
|
long stamp = lock.tryOptimisticRead(); |
569 |
|
Object[] items; |
570 |
< |
if (index >= 0 && (items = array) != null && |
570 |
> |
if (index >= 0 && (items = array) != null && |
571 |
|
index < count && index < items.length) { |
572 |
|
@SuppressWarnings("unchecked") E e = (E)items[index]; |
573 |
|
if (lock.validate(stamp)) |
583 |
|
long stamp = lock.readLock(); |
584 |
|
try { |
585 |
|
Object[] items; |
586 |
< |
if ((items = array) != null && index < items.length && |
586 |
> |
if ((items = array) != null && index < items.length && |
587 |
|
index < count && index >= 0) |
588 |
|
e = (E)items[index]; |
589 |
|
else |
593 |
|
} |
594 |
|
if (oobe) |
595 |
|
throw new ArrayIndexOutOfBoundsException(index); |
596 |
< |
return (E)e; |
596 |
> |
return e; |
597 |
|
} |
598 |
< |
|
598 |
> |
|
599 |
|
public int hashCode() { |
600 |
|
int h; |
601 |
|
final StampedLock lock = this.lock; |
607 |
|
} |
608 |
|
return h; |
609 |
|
} |
610 |
< |
|
610 |
> |
|
611 |
|
public int indexOf(Object o) { |
612 |
|
int idx; |
613 |
|
final StampedLock lock = this.lock; |
742 |
|
if (ret != null) |
743 |
|
return ret; |
744 |
|
} |
745 |
< |
|
745 |
> |
|
746 |
|
throw new ArrayIndexOutOfBoundsException(fromIndex < 0 ? fromIndex : toIndex); |
747 |
|
} |
748 |
|
|
866 |
|
final StampedLock lock = this.lock; |
867 |
|
long stamp = lock.readLock(); |
868 |
|
try { |
869 |
< |
Object[] items; |
869 |
> |
Object[] items; |
870 |
|
int len, n; |
871 |
|
if ((items = array) != null && (len = items.length) > 0 && |
872 |
|
(n = count) <= len) { |
920 |
|
long stamp = lock.tryOptimisticRead(); |
921 |
|
Object[] items; |
922 |
|
int i; |
923 |
< |
if ((items = array) != null && (i = count - 1) >= 0 && |
923 |
> |
if ((items = array) != null && (i = count - 1) >= 0 && |
924 |
|
i < items.length) { |
925 |
|
@SuppressWarnings("unchecked") E e = (E)items[i]; |
926 |
|
if (lock.validate(stamp)) |
973 |
|
try { |
974 |
|
if (index < count) |
975 |
|
idx = findLastIndex(array, o, index, 0); |
976 |
< |
else |
976 |
> |
else |
977 |
|
oobe = true; |
978 |
|
} finally { |
979 |
|
lock.unlockRead(stamp); |
1038 |
|
long stamp = lock.writeLock(); |
1039 |
|
try { |
1040 |
|
Object[] items = array; |
1041 |
< |
int cap = (items == null)? 0 : items.length; |
1041 |
> |
int cap = (items == null) ? 0 : items.length; |
1042 |
|
if (minCapacity - cap > 0) |
1043 |
|
grow(minCapacity); |
1044 |
|
} finally { |
1247 |
|
|
1248 |
|
static final class ReadMostlyVectorSublist<E> |
1249 |
|
implements List<E>, RandomAccess, java.io.Serializable { |
1250 |
< |
static final long serialVersionUID = 3041673470172026059L; |
1250 |
> |
private static final long serialVersionUID = 3041673470172026059L; |
1251 |
|
|
1252 |
|
final ReadMostlyVector<E> list; |
1253 |
|
final int offset; |