5 |
|
*/ |
6 |
|
|
7 |
|
package jsr166e.extra; |
8 |
+ |
|
9 |
|
import jsr166e.StampedLock; |
10 |
|
import java.util.*; |
11 |
|
|
15 |
|
* throughput when invocations of read-only methods by multiple |
16 |
|
* threads are most common. |
17 |
|
* |
18 |
< |
* <p> The iterators returned by this class's {@link #iterator() |
18 |
> |
* <p>The iterators returned by this class's {@link #iterator() |
19 |
|
* iterator} and {@link #listIterator(int) listIterator} methods are |
20 |
|
* best-effort in the presence of concurrent modifications, and do |
21 |
|
* <em>NOT</em> throw {@link ConcurrentModificationException}. An |
94 |
|
* Creates an empty vector with the given initial capacity. |
95 |
|
* |
96 |
|
* @param initialCapacity the initial capacity of the underlying array |
96 |
– |
* |
97 |
|
* @throws IllegalArgumentException if initial capacity is negative |
98 |
|
*/ |
99 |
|
public ReadMostlyVector(int initialCapacity) { |
172 |
|
static int findFirstIndex(Object[] items, Object x, int index, int fence) { |
173 |
|
int len; |
174 |
|
if (items != null && (len = items.length) > 0) { |
175 |
< |
int start = (index < 0)? 0 : index; |
175 |
> |
int start = (index < 0) ? 0 : index; |
176 |
|
int bound = (fence < len) ? fence : len; |
177 |
|
for (int i = start; i < bound; ++i) { |
178 |
|
Object e = items[i]; |
406 |
|
sb.append('['); |
407 |
|
for (;;) { |
408 |
|
Object e = items[i]; |
409 |
< |
sb.append((e == this)? "(this Collection)" : e.toString()); |
409 |
> |
sb.append((e == this) ? "(this Collection)" : e.toString()); |
410 |
|
if (++i < fence) |
411 |
|
sb.append(',').append(' '); |
412 |
|
else |
594 |
|
} |
595 |
|
if (oobe) |
596 |
|
throw new ArrayIndexOutOfBoundsException(index); |
597 |
< |
return (E)e; |
597 |
> |
return e; |
598 |
|
} |
599 |
|
|
600 |
|
public int hashCode() { |
1039 |
|
long stamp = lock.writeLock(); |
1040 |
|
try { |
1041 |
|
Object[] items = array; |
1042 |
< |
int cap = (items == null)? 0 : items.length; |
1042 |
> |
int cap = (items == null) ? 0 : items.length; |
1043 |
|
if (minCapacity - cap > 0) |
1044 |
|
grow(minCapacity); |
1045 |
|
} finally { |
1248 |
|
|
1249 |
|
static final class ReadMostlyVectorSublist<E> |
1250 |
|
implements List<E>, RandomAccess, java.io.Serializable { |
1251 |
< |
static final long serialVersionUID = 3041673470172026059L; |
1251 |
> |
private static final long serialVersionUID = 3041673470172026059L; |
1252 |
|
|
1253 |
|
final ReadMostlyVector<E> list; |
1254 |
|
final int offset; |