8356486: ReverseOrderListView should override reversed() to return base

Reviewed-by: liach, smarks
This commit is contained in:
Per Minborg 2025-05-12 07:12:19 +00:00
parent 45cf32bd2c
commit 43008b42cf

View File

@ -43,9 +43,7 @@ class ReverseOrderListView<E> implements List<E> {
final boolean modifiable;
public static <T> List<T> of(List<T> list, boolean modifiable) {
if (list instanceof ReverseOrderListView<T> rolv) {
return rolv.base;
} else if (list instanceof RandomAccess) {
if (list instanceof RandomAccess) {
return new ReverseOrderListView.Rand<>(list, modifiable);
} else {
return new ReverseOrderListView<>(list, modifiable);
@ -395,6 +393,10 @@ class ReverseOrderListView<E> implements List<E> {
return new ReverseOrderListView<>(base.subList(size - toIndex, size - fromIndex), modifiable);
}
public List<E> reversed() {
return base;
}
static void checkClosedRange(int index, int size) {
if (index < 0 || index > size) {
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);