Closed GoogleCodeExporter closed 9 years ago
Even NavigableMap doesn't have first/last methods returning a value. There's
firstKey(), lastKey(), firstEntry() and lastEntry().
firstKey() and lastKey() don't seem to serve much purpose when you can do
keySet().first() and keySet().last(). And firstEntry()/lastEntry() don't
translate well to a Multimap, where the entries of a Multimap are single
key/value pairs (not key/collection<value> pairs).
(Also, "SortedSet<Object> objs = map.get(map.keySet().first());" doesn't look
that bad to me.)
Louis, any thoughts?
Original comment by cgdecker@google.com
on 3 Jul 2013 at 2:54
I searched the Google code base for 'get[(].*keySet[(][)].*(first|last)[(][)]'
and got no results. I do suspect that TreeMultimap is underused, so probably
there *ought* to be a few callers. Still, it's sounding like this comes up more
frequently for you than for most users.
Hmm, I guess there's another way to do this:
multimap.asMap().firstEntry().getValue()
That's pretty well in line with what you'd need to do with a NavigableMap, as
Colin noted, and it's the kind of thing that asMap() is there for.
(A search for 'asMap.*(first|last)Entry.*getValue' does turn up a couple
results, albeit in tests that might be better served by getOnlyElement or by
assertions against the contents of the multimap as a whole.)
Original comment by cpov...@google.com
on 3 Jul 2013 at 3:19
> multimap.asMap().firstEntry().getValue()
Of course, you'd have to either be ok with the result being a Collection<V> or
do a cast to SortedSet<V>.
Original comment by cgdecker@google.com
on 3 Jul 2013 at 3:22
That's definitely how I'd do it, yeah. It also feels like
TreeMultimap.firstEntry(), as a name, would be kind of ambiguous between an
Entry<K, Collection<V>>, or an Entry<K, V>.
Original comment by wasserman.louis
on 3 Jul 2013 at 4:46
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<issue id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:12
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:17
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:08
Original issue reported on code.google.com by
richardd...@gmail.com
on 3 Jul 2013 at 1:21