Package com.luna.common.map
Class BiMap<K,V>
java.lang.Object
com.luna.common.map.MapWrapper<K,V>
com.luna.common.map.BiMap<K,V>
- Type Parameters:
K
- 键类型V
- 值类型
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<Map.Entry<K,
,V>> Map<K,
V>
双向Map
互换键值对不检查值是否有重复,如果有则后加入的元素替换先加入的元素
值的顺序在HashMap中不确定,所以谁覆盖谁也不确定,在有序的Map中按照先后顺序覆盖,保留最后的值
它与TableMap的区别是,BiMap维护两个Map实现高效的正向和反向查找
互换键值对不检查值是否有重复,如果有则后加入的元素替换先加入的元素
值的顺序在HashMap中不确定,所以谁覆盖谁也不确定,在有序的Map中按照先后顺序覆盖,保留最后的值
它与TableMap的区别是,BiMap维护两个Map实现高效的正向和反向查找
- Since:
- 5.2.6
- See Also:
-
Nested Class Summary
-
Field Summary
Fields inherited from class com.luna.common.map.MapWrapper
DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
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) 获取反向Map根据值获得键merge
(K key, V value, java.util.function.BiFunction<? super V, ? super V, ? extends V> remappingFunction) void
putIfAbsent
(K key, V value) boolean
Methods inherited from class com.luna.common.map.MapWrapper
clone, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, getRaw, hashCode, inverse, isEmpty, iterator, keySet, replace, replace, replaceAll, 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
-
Constructor Details
-
BiMap
构造- Parameters:
raw
- 被包装的Map
-
-
Method Details
-
put
-
putAll
-
remove
-
remove
-
clear
public void clear() -
getInverse
获取反向Map- Returns:
- 反向Map
-
getKey
根据值获得键- Parameters:
value
- 值- Returns:
- 键
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceMap<K,
V> - Overrides:
putIfAbsent
in classMapWrapper<K,
V>
-
computeIfAbsent
- Specified by:
computeIfAbsent
in interfaceMap<K,
V> - Overrides:
computeIfAbsent
in classMapWrapper<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> - Overrides:
computeIfPresent
in classMapWrapper<K,
V>
-
compute
-
merge
-