An implementation of List#subList(int, int).
(final List<E> list, int fromIndex, int toIndex)
| 1112 | * An implementation of {@link List#subList(int, int)}. |
| 1113 | */ |
| 1114 | static <E> List<E> subListImpl(final List<E> list, int fromIndex, int toIndex) { |
| 1115 | List<E> wrapper; |
| 1116 | if (list instanceof RandomAccess) { |
| 1117 | wrapper = |
| 1118 | new RandomAccessListWrapper<E>(list) { |
| 1119 | @Override |
| 1120 | public ListIterator<E> listIterator(int index) { |
| 1121 | return backingList.listIterator(index); |
| 1122 | } |
| 1123 | |
| 1124 | private static final long serialVersionUID = 0; |
| 1125 | }; |
| 1126 | } else { |
| 1127 | wrapper = |
| 1128 | new AbstractListWrapper<E>(list) { |
| 1129 | @Override |
| 1130 | public ListIterator<E> listIterator(int index) { |
| 1131 | return backingList.listIterator(index); |
| 1132 | } |
| 1133 | |
| 1134 | private static final long serialVersionUID = 0; |
| 1135 | }; |
| 1136 | } |
| 1137 | return wrapper.subList(fromIndex, toIndex); |
| 1138 | } |
| 1139 | |
| 1140 | private static class AbstractListWrapper<E> extends AbstractList<E> { |
| 1141 | final List<E> backingList; |
no test coverage detected