mirror of
https://gitee.com/dromara/hutool.git
synced 2025-08-01 10:10:22 +08:00
add FuncKeyMap
This commit is contained in:
parent
71a82e0534
commit
047be5a1f8
@ -10,6 +10,7 @@
|
||||
* 【core 】 FileTypeUtil使用长匹配优先(pr#1457@Github)
|
||||
* 【core 】 IterUtil和CollUtil增加isEqualList方法(issue#I3A3PY@Gitee)
|
||||
* 【crypto 】 增加PBKDF2(issue#1416@Github)
|
||||
* 【core 】 增加FuncKeyMap(issue#1402@Github)
|
||||
|
||||
### Bug修复
|
||||
* 【socket 】 修复Client创建失败资源未释放问题。
|
||||
|
45
hutool-core/src/main/java/cn/hutool/core/map/FuncKeyMap.java
Normal file
45
hutool-core/src/main/java/cn/hutool/core/map/FuncKeyMap.java
Normal file
@ -0,0 +1,45 @@
|
||||
package cn.hutool.core.map;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 自定义函数Key风格的Map
|
||||
*
|
||||
* @param <K> 键类型
|
||||
* @param <V> 值类型
|
||||
* @author Looly
|
||||
* @since 5.6.0
|
||||
*/
|
||||
public class FuncKeyMap<K, V> extends CustomKeyMap<K, V> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Function<Object, K> keyFunc;
|
||||
|
||||
// ------------------------------------------------------------------------- Constructor start
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param m Map
|
||||
* @param keyFunc 自定义KEY的函数
|
||||
*/
|
||||
public FuncKeyMap(Map<K, V> m, Function<Object, K> keyFunc) {
|
||||
super(m);
|
||||
}
|
||||
// ------------------------------------------------------------------------- Constructor end
|
||||
|
||||
/**
|
||||
* 将Key转为驼峰风格,如果key为字符串的话
|
||||
*
|
||||
* @param key KEY
|
||||
* @return 驼峰Key
|
||||
*/
|
||||
@Override
|
||||
protected Object customKey(Object key) {
|
||||
if (null != this.keyFunc) {
|
||||
return keyFunc.apply(key);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user