Skip to content

More simplifications based on recent review comments:#8388

Merged
copybara-service[bot] merged 1 commit intomasterfrom
test_906485124
Apr 28, 2026
Merged

More simplifications based on recent review comments:#8388
copybara-service[bot] merged 1 commit intomasterfrom
test_906485124

Conversation

@copybara-service
Copy link
Copy Markdown
Contributor

More simplifications based on recent review comments:

  • FunctionalEquivalence: Migrate from c.g.common.base.Objects.hashCode to j.u.Objects.hash.
    • (We can't static import it because Equivalance declares its own hash method.)
  • Predicate: Migrate Javadoc from c.g.common.base.Object.equal to j.u.Objects.equals.
  • Predicates: Tweak generics, at which point we can eliminate our local asList method and some explicit type arguments
  • various files: Rename+move Iterators.checkNonnegative to CollectPreconditions.checkNonnegativeIndex to clarify how it differs from CollectPreconditions.checkNonnegative—namely, by throwing IndexOutOfBoundsException instead of IllegalArgumentException.
    • Thanks to Gemini for catching my mistake of trying to use the existing CollectPreconditions.checkNonnegative!
    • This change also changes the error message slightly. I could have left it alone, but I figured it might as well match the format we're using for the similar methods in CollectPreconditions.
    • I had thought that perhaps we could use Preconditions.checkPositionIndex, but (a) that requires a size (which appears in the exception message, so we shouldn't just pass MAX_VALUE) and (b) that throws IllegalArgumentException, too, wait, seriously? What were we thinking in cl/9392102 back in 2008?
  • various files: Remove suppressions of StaticImportPreferred for min/max methods that are in scope. The suppressions are no longer necessary as of cl/897308244, which avoids trying to static import when a method of the same name is already in scope.
    • Or actually, they're not necessary as of the earlier cl/811482021, which removed those suggestions from StaticImportPreferred entirely.
    • I kept the suppression in Booleans. That one exists because Comparator.min does not exist under all versions, so the fix of cl/897308244 is presumably not always sufficient.
      • Again, that's technically not necessary because StaticImportPreferred doesn't make the suggestion at all anymore (for exactly this reason). I suppose that I could tweak it to suggest min/max again as long as we're not inside a Comparator, but StaticImportPreferred is controversial in general, so I don't think that's necessarily worthwhile.
  • various files: Static import min/max where we can (by locally undoing the exclusion for those methods :)).
  • various files in the backport: Static import CollectPreconditions methods in a few more cases.

RELNOTES=n/a

- `FunctionalEquivalence`: Migrate from `c.g.common.base.Objects.hashCode` to `j.u.Objects.hash`.
  - (We can't static import it because `Equivalance` declares its own `hash` method.)
- `Predicate`: Migrate Javadoc from `c.g.common.base.Object.equal` to `j.u.Objects.equals`.
- `Predicates`: Tweak generics, at which point we can eliminate our local `asList` method and some explicit type arguments
- various files: Rename+move `Iterators.checkNonnegative` to `CollectPreconditions.checkNonnegativeIndex` to clarify how it differs from `CollectPreconditions.checkNonnegative`—namely, by throwing `IndexOutOfBoundsException` instead of `IllegalArgumentException`.
  - Thanks to Gemini for catching my mistake of trying to use the existing `CollectPreconditions.checkNonnegative`!
  - This change also changes the error message slightly. I could have left it alone, but I figured it might as well match the format we're using for the similar methods in `CollectPreconditions`.
  - I had thought that perhaps we could use `Preconditions.checkPositionIndex`, but (a) that requires a size (which appears in the exception message, so we shouldn't just pass `MAX_VALUE`) and (b) that [throws `IllegalArgumentException`](https://github.com/google/guava/blob/b9d1fd6875d9267c14dc4063e13af85894ea35d1/guava/src/com/google/common/base/Preconditions.java#L1505), too, wait, seriously? What were we thinking in cl/9392102 back in 2008?
    - I'll bet that many (most?) of our usages of `checkPositionIndex` are wrong. Certainly that's true of [the first one that I looked at](https://github.com/google/guava/blob/b9d1fd6875d9267c14dc4063e13af85894ea35d1/guava/src/com/google/common/collect/Lists.java#L355).
- various files: Remove suppressions of StaticImportPreferred for `min`/`max` methods that are in scope. The suppressions are no longer necessary as of cl/897308244, which avoids trying to static import when a method of the same name is already in scope.
  - Or actually, they're not necessary as of the earlier cl/811482021, which removed those suggestions from StaticImportPreferred entirely.
  - I kept the suppression in `Booleans`. That one exists because `Comparator.min` does not exist under all versions, so the fix of cl/897308244 is presumably not always sufficient.
    - Again, that's technically not necessary because StaticImportPreferred doesn't make the suggestion at all anymore (for exactly this reason). I suppose that I could tweak it to suggest `min`/`max` again as long as we're not inside a `Comparator`, but StaticImportPreferred is controversial in general, so I don't think that's necessarily worthwhile.
- various files: Static import `min`/`max` where we can (by locally undoing the exclusion for those methods :)).
- various files in the backport: Static import `CollectPreconditions` methods in a few more cases.

RELNOTES=n/a
PiperOrigin-RevId: 907127863
@copybara-service copybara-service Bot merged commit 7ae84e3 into master Apr 28, 2026
@copybara-service copybara-service Bot deleted the test_906485124 branch April 28, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant