openrewrite / openrewrite/rewrite-static-analysis
Recipe to prefer `Collection.contains` over multiple OR-ed comparisons
Open
Nobody has claimed this yet.
recipe
- Dominant language
- Java
- Stars
- 62
- Forks
- 112
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 40
Description
What problem are you trying to solve?
Make code more readable.
Describe the situation before applying the recipe
Example
public boolean isWeekend(String day) {
return "Saturday".equals(day) || "Sunday".equals(day);
}
Describe the situation after applying the recipe
public boolean isWeekend(String day) {
return Set.of("Saturday", "Sunday").contains(day);
}
Context
Here the target code is not perfect either. Ideally one would delegate to #617 after this recipe.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue does not name implementation files, tests, or an entry point. Locate the existing recipe definitions and test patterns first, then verify that repeated OR-ed string comparisons are rewritten to Set.of(...).contains(day) and consider how this should interact with recipe #617.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100