Created
September 20, 2012 21:38
-
-
Save dustingetz/3758511 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Map<String, Collection<InboxEntry>> partitionByTaskName(Collection<InboxEntry> delegated) | |
// unfortunately generalizing this requires a higher order function and java makes me not really want to bother | |
// implementing default-dict correctly also needs a higher order function (default value constructor) | |
{ | |
Map<String, Collection<InboxEntry>> taskMap = new HashMap<String, Collection<InboxEntry>>(); // this is a default-dict | |
for (InboxEntry inboxEntry : delegated) | |
{ | |
// the partition key | |
String task_name = inboxEntry.getQueueItemAttributes().fetchSimpleValue("task_name"); | |
Collection<InboxEntry> inboxEntries = taskMap.get(task_name); | |
if (null == inboxEntries) | |
{ | |
inboxEntries = new ArrayList<InboxEntry>(); | |
taskMap.put(task_name, inboxEntries); | |
} | |
inboxEntries.add(inboxEntry); | |
} | |
return taskMap; | |
} |
anakanemison
commented
Sep 20, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment