BiMap(双向映射Map结构)
实现类:
HashBiMap、ImmutableBiMap、EnumBiMap、EnumHashBiMap
当有这种场景时,key需要两个值来确定比如横坐标和纵坐标确定城市位
Map<int x,int y,String string>
但是可惜的是Java并没有这样的数据结构,我们就可以以将x和y抽象到一个对象中,比如Position类,但是这样显然就复杂了我们的开发过程。
Guava提供了Table<R,C,V>数据结构。
我以上描述的并完全正确,Table的操作原理和以上是略有不同的。
Table
Typically, when you are trying to index on more than one key at a time,
you will wind up with something like Map<FirstName, Map<LastName, Person>>, which is ugly and awkward to use.
Guava provides a new collection type, Table, which supports this use case for any "row" type and "column" type.
Table supports a number of views to let you use the data from any angle, including
备注:理解其数据结构在特定场景下使用能获得不错的效益
实现:
HashBasedTable、TreeBasedTable、ImmutableTable、ArrayTable
实际开发中我们可能会遇到,计算某个元素在集合中出现的次数,我们通常的做法就是迭代遍历一下,自己计算。Guava就提供了这么一个数据结构给我们使用Multiset。
同Apache commons Collection的Bag数据结构类似。
Multiset
A collection that supports order-independent equality, like Set, but may have duplicate elements.
A multiset is also sometimes called a bag
实现类:HashMultiset、TreeMultiset、LinkedHashMultiset、ConcurrentHashMultiset、ImmutableMultiset
Multimap
Every experienced Java programmer has, at one point or another, implemented a Map<K, List<V>> or Map<K, Set<V>>, and dealt with the awkwardness of that structure. For example, Map<K, Set<V>> is a typical way to represent an unlabeled directed graph. Guava's Multimap framework makes it easy to handle a mapping from keys to multiple values. A Multimap is a general way to associate keys with arbitrarily many values.
实现:ArrayListMultimap、HashMultimap、TreeMultimap等
范围集合在开发中也会遇到
RangeSet
A RangeSet describes a set of disconnected, nonempty ranges. When adding a range to a mutable RangeSet, any connected ranges are merged together, and empty ranges are ignored.