ArrayListMultimap from google collection

For iterating and storing the nested arrays, it is a good collection which takes care of null, not null etc makes storage and retrieval handy.
Below is a small code snippet of usage while gets the list of object array returned from a hibernate query:
public ListMultimap getAssignmentEventStatus(List assignmentEvents) {
String hql = “select lpa.assignmentEvent.id, lpa.progression from LearningPathAssignment lpa where lpa.assignmentEvent in (:assignmentEvents)”;
List learningPathAssignmentStatus = getSession().createQuery(hql).setParameterList(“assignmentEvents”, assignmentEvents).list();

// Map> map = new HashMap>();

ArrayListMultimap map = ArrayListMultimap. create();
for (Object[] columns : learningPathAssignmentStatus) {
Long id = (Long) columns[0];
LearningPathAssignment.Progression progression = (Progression) columns[1];
map.put(id, progression);
/*
* if (map.get(id) == null) { ArrayList list = new
* ArrayList(); list.add(progression); map.put(id, list); }
* else { List list = map.get(id); list.add(progression); }
*/
return map;
}

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