代码通用

防止多重 if 嵌套

before:

1
2
3
if n:
if m:
//dothing

after:

1
2
3
4
5
if not n:
return
if not m:
return
//do something
Java按照顺序MAP
1
2
3
4
5
6
7
8
9
10
11
Map<String, IntSummaryStatistics> newMap = merchandiseDTOList.stream().collect(
Collectors.groupingBy(
MerchandiseDTO::getEtcCode,
Collectors.summarizingInt(MerchandiseDTO::getMerchandiseNumber)
)
);

Map<String, IntSummaryStatistics> map = newMap.entrySet().stream()
.sorted(Map.Entry.<String, IntSummaryStatistics>comparingByKey().reversed())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
(oldValue, newValue) -> oldValue, LinkedHashMap::new));