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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()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) voidputIfAbsent(K key, V value) booleanMethods 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, valuesMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:
putIfAbsentin interfaceMap<K,V> - Overrides:
putIfAbsentin classMapWrapper<K,V>
-
computeIfAbsent
- Specified by:
computeIfAbsentin interfaceMap<K,V> - Overrides:
computeIfAbsentin classMapWrapper<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> - Overrides:
computeIfPresentin classMapWrapper<K,V>
-
compute
-
merge
-