Recently I have discovered Guava in all its wonder. I have come across an instance where I would like to use a combination of Multimap and Table, basically a Multimap with two keys.
Is there a Guava class to do this or should I just go with Tabe<R, C, Map<T>>
?
A Multimap is a new collection type that is found in Google's Guava library for Java. A Multimap can store more than one value against a key. Both the keys and the values are stored in a collection, and considered to be alternates for Map<K, List<V>> or Map<K, Set<V>> (standard JDK Collections Framework).
The returned table is not thread-safe or serializable, even if the underlying table is. The function is applied lazily, invoked when needed.
Guava's Table is a collection that represents a table like structure containing rows, columns and the associated cell values. The row and the column act as an ordered pair of keys. The row and column act as an ordered pair of keys.
The multimap does not store duplicate key-value pairs. Adding a new key-value pair equal to an existing key-value pair has no effect. Keys and values may be null. All optional multimap methods are supported, and all returned views are modifiable.
As given by one of the project members, Louis Wasserman:
"Conceptual consistency" is not nearly as relevant to us as the metric of "utility times ubiquity." We can't put in the kind of investment that Multitable would require for the sake of a comparatively tiny number of users. For the same reason, we don't include a "three-keyed map," either.
That said, markaf, I can think of another solution for your specific case: use a normal Multimap, but combine the first two fields into a composite key. It doesn't sound like you need to view the rows or the columns of that table, you just want to look up on multiple keys at once.
[And further explains in a second post] Additionally, the composite-key approach generalizes to arbitrary numbers of fields, in contrast to your proposed Multitable interface, which only get you one extra field.
The complete discussion can be found on the Guava Library issue tracker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With