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

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

The newest version!
package cn.hutool.core.map;

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

/**
 * 忽略大小写的Map
* 对KEY忽略大小写,get("Value")和get("value")获得的值相同,put进入的值也会被覆盖 * * @author Looly * * @param 键类型 * @param 值类型 * @since 3.0.2 */ public class CaseInsensitiveMap extends FuncKeyMap { private static final long serialVersionUID = 4043263744224569870L; //------------------------------------------------------------------------- Constructor start /** * 构造 */ public CaseInsensitiveMap() { this(DEFAULT_INITIAL_CAPACITY); } /** * 构造 * * @param initialCapacity 初始大小 */ public CaseInsensitiveMap(int initialCapacity) { this(initialCapacity, DEFAULT_LOAD_FACTOR); } /** * 构造
* 注意此构造将传入的Map所有值复制到当前map中,不修改传入map。 * * @param m 被包装的自定义Map创建器 */ public CaseInsensitiveMap(Map m) { this(DEFAULT_LOAD_FACTOR, m); } /** * 构造 * * @param loadFactor 加载因子 * @param m Map * @since 3.1.2 */ public CaseInsensitiveMap(float loadFactor, Map m) { this(m.size(), loadFactor); this.putAll(m); } /** * 构造 * * @param initialCapacity 初始大小 * @param loadFactor 加载因子 */ public CaseInsensitiveMap(int initialCapacity, float loadFactor) { this(MapBuilder.create(new HashMap<>(initialCapacity, loadFactor))); } /** * 构造
* 注意此构造将传入的Map作为被包装的Map,针对任何修改,传入的Map都会被同样修改。 * * @param emptyMapBuilder 被包装的自定义Map创建器 */ CaseInsensitiveMap(MapBuilder emptyMapBuilder) { // issue#I5VRHW@Gitee 使Function可以被序列化 super(emptyMapBuilder.build(), (Function & Serializable)(key)->{ if (key instanceof CharSequence) { key = key.toString().toLowerCase(); } //noinspection unchecked return (K) key; }); } //------------------------------------------------------------------------- Constructor end }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy