mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-03 12:18:01 +08:00
add method
This commit is contained in:
parent
5ca45ded2b
commit
2d3d41c9f2
@ -24,6 +24,7 @@
|
||||
* 【db 】 ThreadUtil增加createScheduledExecutor和schedule方法(issue#I2NUTC@Gitee)
|
||||
* 【core 】 ImgUtil增加getImage方法(issue#I2DU1Z@Gitee)
|
||||
* 【core 】 DateUtil.beginOfHour(pr#269@Gitee)
|
||||
* 【core 】 MapUtil增加sortByValue(pr#259@Gitee)
|
||||
|
||||
### Bug修复
|
||||
* 【core 】 修复FileUtil.move以及PathUtil.copy等无法自动创建父目录的问题(issue#I2CKTI@Gitee)
|
||||
|
@ -796,6 +796,26 @@ public class MapUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照值排序,可选是否倒序
|
||||
*
|
||||
* @param map 需要对值排序的map
|
||||
* @param <K> 键类型
|
||||
* @param <V> 值类型
|
||||
* @param isDesc 是否倒序
|
||||
* @return Map<k, V> 排序后新的Map
|
||||
* @since 5.5.8
|
||||
*/
|
||||
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map, boolean isDesc) {
|
||||
Map<K, V> result = new LinkedHashMap<>();
|
||||
Comparator<Entry<K, V>> entryComparator = Entry.comparingByValue();
|
||||
if(isDesc){
|
||||
entryComparator = entryComparator.reversed();
|
||||
}
|
||||
map.entrySet().stream().sorted(entryComparator).forEachOrdered(e -> result.put(e.getKey(), e.getValue()));
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建代理Map<br>
|
||||
* {@link MapProxy}对Map做一次包装,提供各种getXXX方法
|
||||
|
Loading…
Reference in New Issue
Block a user