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

cn.hutool.core.map.CamelCaseMap 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 cn.hutool.core.util.StrUtil;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * 驼峰Key风格的Map
* 对KEY转换为驼峰,get("int_value")和get("intValue")获得的值相同,put进入的值也会被覆盖 * * @param 键类型 * @param 值类型 * @author Looly * @since 4.0.7 */ public class CamelCaseMap extends FuncKeyMap { private static final long serialVersionUID = 4043263744224569870L; // ------------------------------------------------------------------------- Constructor start /** * 构造 */ public CamelCaseMap() { this(DEFAULT_INITIAL_CAPACITY); } /** * 构造 * * @param initialCapacity 初始大小 */ public CamelCaseMap(int initialCapacity) { this(initialCapacity, DEFAULT_LOAD_FACTOR); } /** * 构造 * * @param m Map */ public CamelCaseMap(Map m) { this(DEFAULT_LOAD_FACTOR, m); } /** * 构造 * * @param loadFactor 加载因子 * @param m 初始Map,数据会被默认拷贝到一个新的HashMap中 */ public CamelCaseMap(float loadFactor, Map m) { this(m.size(), loadFactor); this.putAll(m); } /** * 构造 * * @param initialCapacity 初始大小 * @param loadFactor 加载因子 */ public CamelCaseMap(int initialCapacity, float loadFactor) { this(MapBuilder.create(new HashMap<>(initialCapacity, loadFactor))); } /** * 构造
* 注意此构造将传入的Map作为被包装的Map,针对任何修改,传入的Map都会被同样修改。 * * @param emptyMapBuilder Map构造器,必须构造空的Map */ CamelCaseMap(MapBuilder emptyMapBuilder) { // issue#I5VRHW@Gitee 使Function可以被序列化 super(emptyMapBuilder.build(), (Function & Serializable)(key) -> { if (key instanceof CharSequence) { key = StrUtil.toCamelCase(key.toString()); } //noinspection unchecked return (K) key; }); } // ------------------------------------------------------------------------- Constructor end }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy