All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.hutool.core.map.FuncKeyMap Maven / Gradle / Ivy

Go to download

Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。

There is a newer version: 5.8.34
Show newest version
package cn.hutool.core.map;

import java.util.Map;
import java.util.function.Function;

/**
 * 自定义函数Key风格的Map
 *
 * @param  键类型
 * @param  值类型
 * @author Looly
 * @since 5.6.0
 */
public class FuncKeyMap extends CustomKeyMap {
	private static final long serialVersionUID = 1L;

	private final Function keyFunc;

	// ------------------------------------------------------------------------- Constructor start

	/**
	 * 构造
* 注意提供的Map中不能有键值对,否则可能导致自定义key失效 * * @param emptyMap Map,提供的空map * @param keyFunc 自定义KEY的函数 */ public FuncKeyMap(Map emptyMap, Function keyFunc) { super(emptyMap); this.keyFunc = keyFunc; } // ------------------------------------------------------------------------- Constructor end /** * 根据函数自定义键 * * @param key KEY * @return 驼峰Key */ @Override protected K customKey(Object key) { if (null != this.keyFunc) { return keyFunc.apply(key); } //noinspection unchecked return (K)key; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy