-
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 Sets{Difference,Intersection}{,Map,Multimap}
and SetsUnion
Refaster rules
#607
Conversation
Looks good. No mutations were possible for these changes. |
5b58f40
to
b653978
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.
Nice improvements @mohamedsamehsalah! 🚀
They make things more clear 😄.
Added a commit and rebased.
Suggested commit message:
Introduce `Sets{Difference,Intersection}{,Map,Multimap}` and `SetsUnion` Refaster rules (#607)
error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetRules.java
Outdated
Show resolved
Hide resolved
...trib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestInput.java
Outdated
Show resolved
Hide resolved
error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetRules.java
Outdated
Show resolved
Hide resolved
@@ -211,4 +214,43 @@ ImmutableSet<T> after(T e1, T e2, T e3, T e4, T e5) { | |||
return ImmutableSet.of(e1, e2, e3, e4, e5); | |||
} | |||
} | |||
|
|||
/** Prefer {@link Sets#intersection(Set, Set)} ()} over more contrived alternatives. */ | |||
static final class SetsIntersection<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.
To be honest, it's a bit hard to decide how we should name these rules. We invoke the same method in the three rules but how we get the set that we pass differs. Till now most cases also use different overloads of a method and based on that we use different words.
I imagine we'd also have something that determines a suffix based on what we pass as the two parameters for Sets#intersection
.
Was doubting whether we want to add the ImmutableCopy
as suffix as well 🤔.
Pushed a suggestion, let's discuss 👀.
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 think that in the end we will want to add ImmutableCopy
(a.o), but fine for me to merge as-is for now.
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.
Added a commit. Did not yet look at union
; will do another pass later to see whether that's a reasonable addition to this PR.
Nice idea @mohamedsamehsalah!
@@ -211,4 +214,43 @@ ImmutableSet<T> after(T e1, T e2, T e3, T e4, T e5) { | |||
return ImmutableSet.of(e1, e2, e3, e4, e5); | |||
} | |||
} | |||
|
|||
/** Prefer {@link Sets#intersection(Set, Set)} ()} over more contrived alternatives. */ | |||
static final class SetsIntersection<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 think that in the end we will want to add ImmutableCopy
(a.o), but fine for me to merge as-is for now.
...trib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestInput.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
ImmutableSet<Integer> testSetsIntersectionMultimap() { | ||
ImmutableMultimap<Integer, Integer> multimap = ImmutableMultimap.of(1, 2); |
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.
It's only a test, but let's avoid the ImmutableMultimap
type (ImmutableListMultimap
and ImmutableSetMultimap
should be preferred.)
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.
What is the reason behind this preference ?
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.
Check the documentation :)
error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetRules.java
Outdated
Show resolved
Hide resolved
|
||
@AfterTemplate | ||
ImmutableSet<T> after(Set<T> set1, Set<T> set2) { | ||
return Sets.intersection(set1, set2).immutableCopy(); |
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.
Next to intersection
there's also difference
. (And union
; see the internal Store PR I filed a few days ago.)
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.
For reference: #2545
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.
@mohamedsamehsalah we try not to link to private things in this repo; I left it out on purpose. 🙃
Looks good. No mutations were possible for these changes. |
Original idea from @werli 🚀 |
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.
Added one more commit :)
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.
Nice, thanks @mohamedsamehsalah! Also thanks to the other reviewers. I got even more than I suggested back then. 😉
5b65230
to
215622d
Compare
Looks good. No mutations were possible for these changes. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Sets{Difference,Intersection}{,Map,Multimap}
and SetsUnion
Refaster rules (#607)
Sets{Difference,Intersection}{,Map,Multimap}
and SetsUnion
Refaster rules (#607)Sets{Difference,Intersection}{,Map,Multimap}
and SetsUnion
Refaster rules
…on` Refaster rules (#607)
Original discussion.Suggested commit message: