An implementation of List#indexOf(Object).
(List<?> list, @Nullable Object element)
| 1073 | |
| 1074 | |
| 1075 | static int indexOfImpl(List<?> list, @Nullable Object element) { |
| 1076 | if (list instanceof RandomAccess) { |
| 1077 | return indexOfRandomAccess(list, element); |
| 1078 | } else { |
| 1079 | ListIterator<?> listIterator = list.listIterator(); |
| 1080 | while (listIterator.hasNext()) { |
| 1081 | if (Objects.equal(element, listIterator.next())) { |
| 1082 | return listIterator.previousIndex(); |
| 1083 | } |
| 1084 | } |
| 1085 | return -1; |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | private static int indexOfRandomAccess(List<?> list, @Nullable Object element) { |
| 1090 | int size = list.size(); |
no test coverage detected