|
20 | 20 | import static com.google.common.collect.Iterables.isEmpty;
|
21 | 21 | import static com.google.common.collect.Iterables.transform;
|
22 | 22 | import static com.google.common.collect.Multisets.immutableEntry;
|
| 23 | +import static com.google.common.truth.NullnessCasts.uncheckedCastNullableTToT; |
23 | 24 |
|
24 | 25 | import com.google.common.base.Equivalence;
|
25 | 26 | import com.google.common.base.Equivalence.Wrapper;
|
@@ -49,15 +50,20 @@ private SubjectUtils() {}
|
49 | 50 |
|
50 | 51 | static final String HUMAN_UNDERSTANDABLE_EMPTY_STRING = "\"\" (empty String)";
|
51 | 52 |
|
52 |
| - static <T extends @Nullable Object> List<T> accumulate(T first, T second, T @Nullable ... rest) { |
| 53 | + static <T extends @Nullable Object> List<T> accumulate(T first, T second, T @Nullable [] rest) { |
53 | 54 | // rest should never be deliberately null, so assume that the caller passed null
|
54 | 55 | // in the third position but intended it to be the third element in the array of values.
|
55 | 56 | // Javac makes the opposite inference, so handle that here.
|
56 | 57 | List<T> items = new ArrayList<>(2 + ((rest == null) ? 1 : rest.length));
|
57 | 58 | items.add(first);
|
58 | 59 | items.add(second);
|
59 | 60 | if (rest == null) {
|
60 |
| - items.add((T) null); |
| 61 | + /* |
| 62 | + * This cast is probably not actually safe as used in IterableSubject.UsingCorrespondence. But |
| 63 | + * that whole API is stuck being type-unsafe unless we re-generify IterableSubject: |
| 64 | + * b/145689657#comment1. |
| 65 | + */ |
| 66 | + items.add(uncheckedCastNullableTToT(null)); |
61 | 67 | } else {
|
62 | 68 | items.addAll(asList(rest));
|
63 | 69 | }
|
@@ -195,15 +201,19 @@ protected int doHash(Object o) {
|
195 | 201 | * elements and even to output different elements on different lines.
|
196 | 202 | */
|
197 | 203 | static final class DuplicateGroupedAndTyped {
|
198 |
| - final NonHashingMultiset<?> valuesAndMaybeTypes; |
199 |
| - final @Nullable String homogeneousTypeToDisplay; |
| 204 | + private final NonHashingMultiset<?> valuesAndMaybeTypes; |
| 205 | + private final @Nullable String homogeneousTypeToDisplay; |
200 | 206 |
|
201 | 207 | DuplicateGroupedAndTyped(
|
202 | 208 | NonHashingMultiset<?> valuesAndMaybeTypes, @Nullable String homogeneousTypeToDisplay) {
|
203 | 209 | this.valuesAndMaybeTypes = valuesAndMaybeTypes;
|
204 | 210 | this.homogeneousTypeToDisplay = homogeneousTypeToDisplay;
|
205 | 211 | }
|
206 | 212 |
|
| 213 | + @Nullable String getHomogeneousTypeToDisplay() { |
| 214 | + return homogeneousTypeToDisplay; |
| 215 | + } |
| 216 | + |
207 | 217 | int totalCopies() {
|
208 | 218 | return valuesAndMaybeTypes.totalCopies();
|
209 | 219 | }
|
@@ -257,10 +267,10 @@ public String toString() {
|
257 | 267 | * <p>Example: {@code hasMatchingToStringPair([1L, 2L], [1]) == true}
|
258 | 268 | */
|
259 | 269 | static boolean hasMatchingToStringPair(Iterable<?> items1, Iterable<?> items2) {
|
260 |
| - if (isEmpty(items1) || isEmpty(items2)) { |
261 |
| - return false; // Bail early to avoid calling hashCode() on the elements unnecessarily. |
262 |
| - } |
263 |
| - return !retainMatchingToString(items1, items2).isEmpty(); |
| 270 | + // Bail early for empty iterables to avoid calling hashCode() on the elements unnecessarily. |
| 271 | + return !isEmpty(items1) |
| 272 | + && !isEmpty(items2) |
| 273 | + && !retainMatchingToString(items1, items2).isEmpty(); |
264 | 274 | }
|
265 | 275 |
|
266 | 276 | static String objectToTypeName(@Nullable Object item) {
|
|
0 commit comments