Files
Louis Vignier af042e1eb6 IJ-CR-7352 [java] Fix inspection descriptions
GitOrigin-RevId: 6690332575359f1f9bab67d976756c570004179e
2021-03-19 19:22:43 +00:00

26 lines
890 B
Java

// "Fix all 'Comparator method 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);
}
}