Two Guava Collections

Today I wrote two different Guava Collections as answer to two different StackOverflow Questions:

Java data Structure and
Comparator and equals()

The first requested a Map where the keys are Enums and the values are sorted collections.

In my answer, I implemented a Guava MultiMap that does just that. It uses EnumMap internally if it knows the enum’s type and a HashMap or a user-supplied map otherwise (each of these three Constructors has a sibling with a custom comparator that sorts the values).

The second was apparently based on the first and dealt with the problem that the OP would like to use a SortedSet, but the business objects did not have a valid compareTo() / equals() relation, so I suggested that a sorted List would be better. I implemented such a List using Guava’s ForwardingList as base and redirecting the logic to an internal ArrayList.

Advertisements
This entry was posted in Guava, Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s