648 |
|
long seq = lock.awaitAvailability(); |
649 |
|
int n = count; |
650 |
|
Object[] items = array; |
651 |
– |
if (n > items.length) |
652 |
– |
continue; |
653 |
– |
boolean outOfBounds = (index < 0 || index >= n); |
651 |
|
@SuppressWarnings("unchecked") |
652 |
< |
E e = outOfBounds ? null : (E) items[index]; |
652 |
> |
E e = (index < items.length) ? (E) items[index] : null; |
653 |
|
if (lock.getSequence() == seq) { |
654 |
< |
if (outOfBounds) |
654 |
> |
if (index >= n) |
655 |
|
throw new ArrayIndexOutOfBoundsException(index); |
656 |
< |
else |
660 |
< |
return e; |
656 |
> |
return e; |
657 |
|
} |
658 |
|
} |
659 |
|
} |
663 |
|
} |
664 |
|
|
665 |
|
public int indexOf(Object o) { |
666 |
< |
final SequenceLock lock = this.lock; |
671 |
< |
for (;;) { |
672 |
< |
long seq = lock.awaitAvailability(); |
673 |
< |
Object[] items = array; |
674 |
< |
int n = count; |
675 |
< |
if (n <= items.length) { |
676 |
< |
for (int i = 0; i < n; ++i) { |
677 |
< |
Object e = items[i]; |
678 |
< |
if (lock.getSequence() != seq) { |
679 |
< |
lock.lock(); |
680 |
< |
try { |
681 |
< |
return rawIndexOf(o, 0, count); |
682 |
< |
} finally { |
683 |
< |
lock.unlock(); |
684 |
< |
} |
685 |
< |
} |
686 |
< |
else if ((o == null) ? e == null : o.equals(e)) |
687 |
< |
return i; |
688 |
< |
} |
689 |
< |
return -1; |
690 |
< |
} |
691 |
< |
} |
666 |
> |
return indexOf(o, 0); |
667 |
|
} |
668 |
|
|
669 |
|
public boolean isEmpty() { |
929 |
|
if (index < 0) |
930 |
|
ex = true; |
931 |
|
else |
932 |
< |
idx = rawIndexOf(o, 0, count); |
932 |
> |
idx = rawIndexOf(o, index, count); |
933 |
|
} finally { |
934 |
|
lock.unlock(); |
935 |
|
} |