if (!sharedWithMe.isEmpty()) {
final List<TodoItem> list = entityManager.createNamedQuery("allSharedItems", TodoItem.class)
.setParameter("userIds", sharedWithMe).getResultList();
String userName = null;
SharedList currentList = null;
for (TodoItem todoItem : list) {
if (!todoItem.getLoginName().equals(userName)) {
currentList = new SharedList(userNames.get(todoItem.getLoginName()).getShortName());
sharedLists.add(currentList);
userName = todoItem.getLoginName();
}
currentList.getItems().add(todoItem);
}
}
return sharedLists;
}