}
private List<EntityGroup> createTopicGroups(Collection<INews> input) {
/* Default Group */
EntityGroup gDefault = new EntityGroup(Group.NO_TOPIC.ordinal(), GROUP_CATEGORY_ID, Group.NO_TOPIC.getName());
Map<String, EntityGroup> groupCache = new HashMap<String, EntityGroup>();
groupCache.put(Group.NO_TOPIC.getName(), gDefault);
/* Group Input */
int nextId = Group.NO_TOPIC.ordinal() + TITLE_ID_BEGIN;
for (Object object : input) {
if (object instanceof INews) {
INews news = (INews) object;
EntityGroup group = gDefault;
/* Normalize Title */
String normalizedTitle = ModelUtils.getHeadline(news);
normalizedTitle = ModelUtils.normalizeTitle(normalizedTitle);
/* Determine Group ID */
String groupId;
if (StringUtils.isSet(news.getInReplyTo()))
groupId = news.getInReplyTo();
else
groupId = normalizedTitle;
/* Add or Create Group */
if (StringUtils.isSet(groupId)) {
group = groupCache.get(groupId);
/* Create new Group */
if (group == null) {
group = new EntityGroup(nextId++, GROUP_CATEGORY_ID, normalizedTitle);
groupCache.put(groupId, group);
}
}
/* Add to Group */