Add pattern for Comparator combinators
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
IntelliJ has the [ComparatorCombinators](https://www.jetbrains.com/help/inspectopedia/ComparatorCombinators.html) inspection.
Before:
```java
myList.sort((person1, person2) -> person1.getName().compareTo(person2.getName()));
myList2.sort((person1, person2) -> {
int res = person1.first().compareTo(person2.first());
if(res == 0) res = person1.second().compareTo(person2.second());
if(res == 0) res = person1.third() - person2.third();
return res;
});
```
After:
```java
myList.sort(Comparator.comparing(Person::getName));
myList2.sort(Comparator.comparing(Person::first)
.thenComparing(Person::second)
.thenComparingInt(Person::third));
```
Contributor guide
Research direction
The issue provides Java before-and-after examples but no source file or test path. Start by locating existing comparator-related checks and their regression tests, then compare the implementation's supported patterns with the examples; done means the listed comparator chains are recognized and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100