public void rebuildCommentGroups() { commentGroups = new ArrayList<CommentGroup>(); Comment prevComment = null; for (Comment comment : comments) { if (prevComment != null) { CommentGroup group = new CommentGroup(); group.setDateString(comment.getDate()); if (commentGroups.contains(group)) { int index = commentGroups.indexOf(group); group = commentGroups.get(index); group.addComment(comment); } else { addNewCommentGroup(comment); } } else { addNewCommentGroup(comment); } prevComment = comment; } }
private void addNewCommentGroup(Comment comment) { CommentGroup group = new CommentGroup(); group.setDateString(comment.getDate()); List<Comment> groupComments = new ArrayList<Comment>(); groupComments.add(comment); group.setComments(groupComments); commentGroups.add(group); }