Package com.luna.common.map
Class MapWrapper<K,V>
java.lang.Object
com.luna.common.map.MapWrapper<K,V>
- Type Parameters:
K- 键类型V- 值类型
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Map.Entry<K,,V>> Map<K,V>
- Direct Known Subclasses:
BiMap
public class MapWrapper<K,V>
extends Object
implements Map<K,V>, Iterable<Map.Entry<K,V>>, Serializable, Cloneable
Map包装类,通过包装一个已有Map实现特定功能。例如自定义Key的规则或Value规则
- Since:
- 4.3.3
- Author:
- looly
- See Also:
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int默认初始大小protected static final float默认增长因子 -
Constructor Summary
ConstructorsConstructorDescriptionMapWrapper(java.util.function.Supplier<Map<K, V>> mapFactory) 构造
通过传入一个Map从而确定Map的类型,子类需创建一个空的Map,而非传入一个已有Map,否则值可能会被修改MapWrapper(Map<K, V> raw) 构造 -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()MapWrapper<K,V> clone()computeIfAbsent(K key, java.util.function.Function<? super K, ? extends V> mappingFunction) computeIfPresent(K key, java.util.function.BiFunction<? super K, ? super V, ? extends V> remappingFunction) booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()booleanvoidgetOrDefault(Object key, V defaultValue) getRaw()获取原始的MapinthashCode()static <K,V> Map<V, K> Map的键和值互换
互换键值对不检查值是否有重复,如果有则后加入的元素替换先加入的元素
值的顺序在HashMap中不确定,所以谁覆盖谁也不确定,在有序的Map中按照先后顺序覆盖,保留最后的值booleanisEmpty()iterator()keySet()merge(K key, V value, java.util.function.BiFunction<? super V, ? super V, ? extends V> remappingFunction) voidputIfAbsent(K key, V value) booleanbooleanvoidreplaceAll(java.util.function.BiFunction<? super K, ? super V, ? extends V> function) intsize()toString()values()Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_LOAD_FACTOR
protected static final float DEFAULT_LOAD_FACTOR默认增长因子- See Also:
-
DEFAULT_INITIAL_CAPACITY
protected static final int DEFAULT_INITIAL_CAPACITY默认初始大小- See Also:
-
-
Constructor Details
-
MapWrapper
构造
通过传入一个Map从而确定Map的类型,子类需创建一个空的Map,而非传入一个已有Map,否则值可能会被修改- Parameters:
mapFactory- 空Map创建工厂- Since:
- 5.8.0
-
MapWrapper
构造- Parameters:
raw- 被包装的Map
-
-
Method Details
-
inverse
Map的键和值互换
互换键值对不检查值是否有重复,如果有则后加入的元素替换先加入的元素
值的顺序在HashMap中不确定,所以谁覆盖谁也不确定,在有序的Map中按照先后顺序覆盖,保留最后的值- Type Parameters:
K- 键和值类型V- 键和值类型- Parameters:
map- Map对象,键值类型必须一致- Returns:
- 互换后的Map
- Since:
- 5.2.6
-
getRaw
获取原始的Map- Returns:
- Map
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
values
-
keySet
-
entrySet
-
iterator
-
equals
-
hashCode
public int hashCode() -
toString
-
forEach
-
replaceAll
- Specified by:
replaceAllin interfaceMap<K,V>
-
putIfAbsent
- Specified by:
putIfAbsentin interfaceMap<K,V>
-
remove
-
replace
-
replace
-
computeIfAbsent
- Specified by:
computeIfAbsentin interfaceMap<K,V>
-
getOrDefault
- Specified by:
getOrDefaultin interfaceMap<K,V>
-
computeIfPresent
public V computeIfPresent(K key, java.util.function.BiFunction<? super K, ? super V, ? extends V> remappingFunction) - Specified by:
computeIfPresentin interfaceMap<K,V>
-
compute
-
merge
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-