An implementation of List#lastIndexOf(Object).
(List<?> list, @Nullable Object element)
| 1110 | |
| 1111 | |
| 1112 | static int lastIndexOfImpl(List<?> list, @Nullable Object element) { |
| 1113 | if (list instanceof RandomAccess) { |
| 1114 | return lastIndexOfRandomAccess(list, element); |
| 1115 | } else { |
| 1116 | ListIterator<?> listIterator = list.listIterator(list.size()); |
| 1117 | while (listIterator.hasPrevious()) { |
| 1118 | if (Objects.equal(element, listIterator.previous())) { |
| 1119 | return listIterator.nextIndex(); |
| 1120 | } |
| 1121 | } |
| 1122 | return -1; |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | private static int lastIndexOfRandomAccess(List<?> list, @Nullable Object element) { |
| 1127 | if (element == null) { |
no test coverage detected