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

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

There is a newer version: 5.8.33
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