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
Modifier and TypeFieldDescriptionprotected static final int
默认初始大小protected static final float
默认增长因子 -
Constructor Summary
ConstructorDescriptionMapWrapper
(java.util.function.Supplier<Map<K, V>> mapFactory) 构造
通过传入一个Map从而确定Map的类型,子类需创建一个空的Map,而非传入一个已有Map,否则值可能会被修改MapWrapper
(Map<K, V> raw) 构造 -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
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) boolean
containsKey
(Object key) boolean
containsValue
(Object value) entrySet()
boolean
void
getOrDefault
(Object key, V defaultValue) getRaw()
获取原始的Mapint
hashCode()
static <K,
V> Map<V, K> Map的键和值互换
互换键值对不检查值是否有重复,如果有则后加入的元素替换先加入的元素
值的顺序在HashMap中不确定,所以谁覆盖谁也不确定,在有序的Map中按照先后顺序覆盖,保留最后的值boolean
isEmpty()
iterator()
keySet()
merge
(K key, V value, java.util.function.BiFunction<? super V, ? super V, ? extends V> remappingFunction) void
putIfAbsent
(K key, V value) boolean
boolean
void
replaceAll
(java.util.function.BiFunction<? super K, ? super V, ? extends V> function) int
size()
toString()
values()
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in 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:
replaceAll
in interfaceMap<K,
V>
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceMap<K,
V>
-
remove
-
replace
-
replace
-
computeIfAbsent
- Specified by:
computeIfAbsent
in interfaceMap<K,
V>
-
getOrDefault
- Specified by:
getOrDefault
in interfaceMap<K,
V>
-
computeIfPresent
public V computeIfPresent(K key, java.util.function.BiFunction<? super K, ? super V, ? extends V> remappingFunction) - Specified by:
computeIfPresent
in interfaceMap<K,
V>
-
compute
-
merge
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-