Interface BiMap<K,V>
- Type Parameters:
K- key type | 键类型V- value type | 值类型
- All Superinterfaces:
Map<K,V>
- All Known Implementing Classes:
HashBiMap
BiMap - Bidirectional Map Interface
BiMap - 双向映射接口
A bidirectional map where both keys and values must be unique. Provides inverse view for value-to-key lookups.
双向映射,键和值都必须唯一。提供反向视图用于值到键的查找。
Features | 主要功能:
- Bidirectional mapping - 双向映射
- Unique keys and values - 唯一的键和值
- Inverse view - 反向视图
- Force put operation - 强制放入操作
Usage Examples | 使用示例:
// Create BiMap - 创建 BiMap
BiMap<String, Integer> bimap = HashBiMap.create();
// Put entries - 放入条目
bimap.put("one", 1);
bimap.put("two", 2);
// Get by key - 通过键获取
Integer value = bimap.get("one"); // 1
// Get inverse view - 获取反向视图
BiMap<Integer, String> inverse = bimap.inverse();
String key = inverse.get(1); // "one"
// Force put (replaces existing mapping) - 强制放入
bimap.forcePut("three", 1); // removes "one" -> 1
Performance | 性能特性:
- get: O(1) for hash-based - get: O(1) 基于哈希
- put: O(1) for hash-based - put: O(1) 基于哈希
- inverse: O(1) - inverse: O(1)
Security | 安全性:
- Thread-safe: Implementation dependent - 线程安全: 取决于实现
- Null-safe: No (nulls not allowed) - 空值安全: 否(不允许空值)
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
-
Method Summary
Methods inherited from interface Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size
-
Method Details
-
put
Associates the specified value with the specified key. Throws exception if value already exists. 将指定值与指定键关联。如果值已存在则抛出异常。- Specified by:
putin interfaceMap<K,V> - Parameters:
key- the key | 键value- the value | 值- Returns:
- the previous value, or null | 之前的值,或 null
- Throws:
IllegalArgumentException- if value already present | 如果值已存在
-
forcePut
-
inverse
-
values
-