Skip to content
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

Merged
merged 4 commits into from
May 3, 2023

Conversation

mohamedsamehsalah
Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah commented May 1, 2023

Original discussion.

Suggested commit message:

Introduce `Sets{Difference,Intersection}{,Map,Multimap}` and `SetsUnion` Refaster rules (#607)

@github-actions
Copy link

github-actions bot commented May 1, 2023

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie force-pushed the mohamedsamehsalah/sets-intersection branch from 5b58f40 to b653978 Compare May 2, 2023 07:19
Copy link
Member

@rickie rickie left a 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)

@@ -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> {
Copy link
Member

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 👀.

Copy link
Member

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.

@rickie rickie added this to the 0.10.0 milestone May 2, 2023
@github-actions
Copy link

github-actions bot commented May 2, 2023

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@Stephan202 Stephan202 left a 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> {
Copy link
Member

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.

}

ImmutableSet<Integer> testSetsIntersectionMultimap() {
ImmutableMultimap<Integer, Integer> multimap = ImmutableMultimap.of(1, 2);
Copy link
Member

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.)

Copy link
Contributor Author

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 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the documentation :)


@AfterTemplate
ImmutableSet<T> after(Set<T> set1, Set<T> set2) {
return Sets.intersection(set1, set2).immutableCopy();
Copy link
Member

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.)

Copy link
Contributor Author

@mohamedsamehsalah mohamedsamehsalah May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: #2545

Copy link
Member

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. 🙃

@github-actions
Copy link

github-actions bot commented May 2, 2023

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@mohamedsamehsalah
Copy link
Contributor Author

@Stephan202
...Nice idea @mohamedsamehsalah!

Original idea from @werli 🚀

Copy link
Member

@Stephan202 Stephan202 left a 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 :)

@github-actions
Copy link

github-actions bot commented May 2, 2023

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@werli werli left a 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. 😉

@rickie rickie force-pushed the mohamedsamehsalah/sets-intersection branch from 5b65230 to 215622d Compare May 3, 2023 13:33
@github-actions
Copy link

github-actions bot commented May 3, 2023

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@rickie rickie merged commit 7d728e9 into master May 3, 2023
@rickie rickie deleted the mohamedsamehsalah/sets-intersection branch May 3, 2023 14:56
@rickie rickie changed the title Prefer Sets#intersection over more contrived alternatives. Introduce Sets{Difference,Intersection}{,Map,Multimap} and SetsUnion Refaster rules (#607) May 5, 2023
@rickie rickie changed the title Introduce Sets{Difference,Intersection}{,Map,Multimap} and SetsUnion Refaster rules (#607) Introduce Sets{Difference,Intersection}{,Map,Multimap} and SetsUnion Refaster rules May 5, 2023
philleonard pushed a commit that referenced this pull request May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants