mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
IDEA-207434 Comprator.comparing(Map.Entry::getKey) -> Map.Entry.comparingByKey()
GitOrigin-RevId: 9481f1e30f7262576ae132295fa27f9777396896
This commit is contained in:
committed by
intellij-monorepo-bot
parent
58b4cb2dd3
commit
6fdffcb1b5
+26
@@ -0,0 +1,26 @@
|
||||
// "Fix all 'Comparator can be simplified' problems in file" "true"
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
Map<String, Integer> unsortMap = new HashMap<>();
|
||||
unsortMap.put("z", 10);
|
||||
unsortMap.put("b", 5);
|
||||
unsortMap.put("a", 6);
|
||||
unsortMap.put("c", 20);
|
||||
unsortMap.put("d", 1);
|
||||
|
||||
Map<String, Integer> result = unsortMap.entrySet().stream()
|
||||
.sorted(Entry.comparingByValue(Comparator.reverseOrder()))
|
||||
.sorted(Entry.comparingByValue())
|
||||
.sorted(Entry.comparingByKey())
|
||||
.sorted(Entry.comparingByKey(String.CASE_INSENSITIVE_ORDER))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
|
||||
(oldValue, newValue) -> oldValue, LinkedHashMap::new));
|
||||
|
||||
System.out.println("Sorted...");
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Fix all 'Comparator can be simplified' problems in file" "true"
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
Map<String, Integer> unsortMap = new HashMap<>();
|
||||
unsortMap.put("z", 10);
|
||||
unsortMap.put("b", 5);
|
||||
unsortMap.put("a", 6);
|
||||
unsortMap.put("c", 20);
|
||||
unsortMap.put("d", 1);
|
||||
|
||||
Map<String, Integer> result = unsortMap.entrySet().stream()
|
||||
.sorted(Comparator.<caret>comparing(Map.Entry::getValue, Comparator.reverseOrder()) )
|
||||
.sorted(Comparator.comparing(Map.Entry::getValue) )
|
||||
.sorted(Comparator.comparing(Map.Entry::getKey) )
|
||||
.sorted(Comparator.comparing(Entry::getKey, String.CASE_INSENSITIVE_ORDER) )
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
|
||||
(oldValue, newValue) -> oldValue, LinkedHashMap::new));
|
||||
|
||||
System.out.println("Sorted...");
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user