mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
27 lines
983 B
HTML
27 lines
983 B
HTML
<html>
|
|
<body>
|
|
Reports <code>Comparator</code> instances defined as lambda expressions that could be expressed using
|
|
<code>Comparator.comparing()</code> calls.
|
|
Chained comparisons which can be replaced by <code>Comparator.thenComparing()</code> expression are also reported.
|
|
<p>Example:</p>
|
|
<pre><code>
|
|
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;
|
|
});
|
|
</code></pre>
|
|
<p>After the quick-fixes are applied:</p>
|
|
<pre><code>
|
|
myList.sort(Comparator.comparing(Person::getName));
|
|
|
|
myList2.sort(Comparator.comparing(Person::first)
|
|
.thenComparing(Person::second)
|
|
.thenComparingInt(Person::third));
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
</body>
|
|
</html> |