Guava collections -- BiMap
来源:互联网 发布:电脑桌面时间软件 编辑:程序博客网 时间:2024/05/22 03:48
Guava全文介绍地址:Google Guava
这次主要介绍是的是com.google.common.collect.BiMap.Guava中BiMap接口是继Map。一个bimap(或称之为bidirectional map[双向Map])是一个映射,保证Map中的key值与value值的唯一性。这种约束使bimaps支持一个“inverse view”,就是另外一个bimap包含同样的entries,但是它的keys和value值是相反的。
下面就介绍一个BiMap的主要用法:
1、保证key与value的唯一性
@Test(expected = IllegalArgumentException.class) public void testBiMapSameValueDifferentKey() throws Exception { BiMap<String,String> biMap = HashBiMap.create(); biMap.put("1","Tom"); biMap.put("2","Tom"); }
2、强制添加
@Test public void testBiMapForcePut() throws Exception { BiMap<String,String> biMap = HashBiMap.create(); biMap.put("1","Tom"); biMap.forcePut("2","Tom"); assertThat(biMap.containsKey("1"),is(false)); assertThat(biMap.containsKey("2"),is(true)); }
3、inverse view
@Test public void testBiMapInverse() throws Exception { BiMap<String,String> biMap = HashBiMap.create(); biMap.put("1","Tom"); biMap.put("2","Harry"); assertThat(biMap.get("1"),is("Tom")); assertThat(biMap.get("2"),is("Harry")); BiMap<String,String> inverseMap = biMap.inverse(); assertThat(inverseMap.get("Tom"),is("1")); assertThat(inverseMap.get("Harry"),is("2")); }
更多功能等待你的发现。
0 0
- Guava collections -- BiMap
- Guava学习之BiMap
- [Guava]——BiMap
- Java-类库-Guava-Bimap
- guava之BiMap
- Guava使用之BiMap
- Google Guava学习之BiMap
- Guava collections -- Immutable Collections
- Guava学习——集合类BiMap
- Guava类库学习--Multiset+Multimap+BiMap
- Google Guava集合BiMap和Multimap
- [Guava源码日报](11)BiMap
- guava之MultiSet、MultiMap和BiMap
- Guava学习笔记:Guava新增集合类型-Bimap
- Guava学习笔记:Guava新增集合类型-Bimap
- Guava学习笔记【9】:Guava新增集合类型-Bimap
- Google Guava学习(7)-Guava集合工具 Bimap接口
- Google Guava Collections
- Android判断EditText输入的数字、中文还是字母方法
- 在Fragment、PreferenceFragment和OnPreferenceClickListener()里获取Activity
- React Native控件之Touchable*系列组件详解(28)
- 走遍世界 —— 海地
- 读书笔记:《算法导论》,写在前面
- Guava collections -- BiMap
- Java实习生对于接口及使用的理解
- hdu 5304 基尔霍夫矩阵
- LUA学习之一 初次接触
- 设置centos 和win文件共享
- 跟着w3c标准来探讨display:none;与visibility:hidden;的区别
- 名字覆盖问题与命名规范
- 如何阅读apple官方文档
- C语言学习-FirstC