An implementation of List#equals(Object).
(List<?> thisList, @Nullable Object other)
| 1028 | |
| 1029 | |
| 1030 | static boolean equalsImpl(List<?> thisList, @Nullable Object other) { |
| 1031 | if (other == checkNotNull(thisList)) { |
| 1032 | return true; |
| 1033 | } |
| 1034 | if (!(other instanceof List)) { |
| 1035 | return false; |
| 1036 | } |
| 1037 | List<?> otherList = (List<?>) other; |
| 1038 | int size = thisList.size(); |
| 1039 | if (size != otherList.size()) { |
| 1040 | return false; |
| 1041 | } |
| 1042 | if (thisList instanceof RandomAccess && otherList instanceof RandomAccess) { |
| 1043 | // avoid allocation and use the faster loop |
| 1044 | for (int i = 0; i < size; i++) { |
| 1045 | if (!Objects.equal(thisList.get(i), otherList.get(i))) { |
| 1046 | return false; |
| 1047 | } |
| 1048 | } |
| 1049 | return true; |
| 1050 | } else { |
| 1051 | return Iterators.elementsEqual(thisList.iterator(), otherList.iterator()); |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | /** |
| 1056 | * An implementation of {@link List#addAll(int, Collection)}. |
no test coverage detected