Google Collection API (Google Guava) Types
Google Collections API (Google Guava) provide additional collection types to offer additional but common features. These advanced types are derived from Java Collection types, hence they continue to offer the features of underlying Java type. In addition to that there are many additional features encapsulated in these new types, so that we can directly use them instead of re-inventing wheel. Let us see these interfaces and features of those interfaces.
Google Collection API ( Google Guava) Types Details:
Multimap: This interface is based on Map interface. Map stores key-value pairs. Map interface does not allow duplicates. Multimap also stores key-value pairs, just that it allows duplicate keys. This interface is also Google Web Toolkit compatible. In addition to the java.util.Map methods, the additional methods are – containsEntry() which checks if a key-value pair exists in MultiMap, keys() returning a MultiSet of keys, and few other methods.
SetMultiMap: This combines features of a Set and a MultiMap. This interface extends from MultiMap. Though the key-value pairs of SetMultiMap can have duplicate keys, but it cannot contain duplicate values. This provides duplicate key feature of MultiMap and adheres to the contract of Set by containing only unique key values. This means the values inserted against a key, forming a collection, will not be duplicate.
ListMultiMap: This is another extension of MultiMap. This allows duplicate key-value pairs. The value part of a pair fulfills List contract. List contract includes maintaining order of (collection) values inserted against the key and random access of these values.
SortedSetMultiMap: This extends from SetMultiMap. Collection entered as a value against a key is sorted.
MultiSet: Alternate name of this google collection API type is bag. This is has origin from set but differs in basic constraint of set, which is – in mathematics a set cannot have duplicate values. Multiset can have. If the values are equal in Multiset then you can get ‘count’ of those values.
BitMap: It can also be called as invertible Map. It guaranties uniqueness of both keys and values. Hence it can be inverted to convert values into keys.
ClassToInstanceMap: This allows type safe value addition to the map. Raw Java types e.g. Collection can be added to the Map.