-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Collections{Max,Min,Sort}
Refaster rules
#1297
Conversation
Looks good. No mutations were possible for these changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following are flagged by default as a warning in Intellij
static final class SortCollections<T extends Comparable<? super T>> { | ||
@BeforeTemplate | ||
void before(List<T> collection) { | ||
Collections.sort(collection, naturalOrder()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line.
@BeforeTemplate | ||
T before(Collection<T> collection) { | ||
return Refaster.anyOf( | ||
Collections.min(collection, naturalOrder()), Collections.max(collection, reverseOrder())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collections.max(collection, reverseOrder())
@BeforeTemplate | ||
T before(Collection<T> collection) { | ||
return Refaster.anyOf( | ||
Collections.max(collection, naturalOrder()), Collections.min(collection, reverseOrder())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collections.min(collection, reverseOrder())
4982575
to
1ca77b4
Compare
527cf0d
to
81d35e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased and added a commit. Suggested commit message:
Introduce `Collections{Max,Min,Sort}` Refaster rules (#1297)
While there, rename `{Max,Min}OfCollection` to
`Collections{Max,Min}WithComparator`.
@@ -243,18 +245,77 @@ int after(T value1, T value2) { | |||
} | |||
} | |||
|
|||
/** Prefer {@link Collections#sort(List)} over more verbose alternatives. */ | |||
static final class SortCollections<T extends Comparable<? super T>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following our naming scheme:
static final class SortCollections<T extends Comparable<? super T>> { | |
static final class SortCollections<T extends Comparable<? super T>> { |
} | ||
|
||
/** Prefer {@link Collections#min(Collection)} over more verbose alternatives. */ | ||
static final class MinOfCollection<T extends Comparable<? super T>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see how this matches the other rule (should have thought this through better in the other PR 😬), but I realize this one should be named CollectionsMin
, and similarly before for the "max" rule. I'll also move it up a bit and rename the MinOfCollectionComparator
variant to CollectionsMinWithComparator
; the "with" naming is also used elsewhere. (Not sure this'll be the final naming we'll settle on 🤔.)
@@ -107,6 +108,24 @@ ImmutableSet<Integer> testCompareTo() { | |||
Comparator.<String>reverseOrder().compare("baz", "qux")); | |||
} | |||
|
|||
void testSortCollections() { | |||
Collections.sort(List.of("foo", "bar"), naturalOrder()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collections.sort(List.of("foo", "bar"), naturalOrder()); | |
Collections.sort(ImmutableList.of("foo", "bar"), naturalOrder()); |
ImmutableSet<String> collection = ImmutableSet.of("foo", "bar"); | ||
return ImmutableSet.of( | ||
Collections.min(collection, naturalOrder()), Collections.max(collection, reverseOrder())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally don't create separate variables in cases like these.
{MaxOf,MinOf,Sort}Collection
refaster rulesCollections{Max,Min,Sort}
Refaster rules
Looks good. No mutations were possible for these changes. |
81d35e6
to
7a53dc3
Compare
Looks good. No mutations were possible for these changes. |
While here, rename original `{MaxOf,MinOf}Collection` to `{MaxOf,MinOf}CollectionComparator`.
7a53dc3
to
ae12270
Compare
Quality Gate passedIssues Measures |
Looks good. No mutations were possible for these changes. |
## Built on top of #1276Suggested commit message: