+ private List<Object> collectEventsForChangesInSone(Sone oldSone,
+ final Sone newSone) {
+ final List<Object> events = new ArrayList<Object>();
+ SoneChangeDetector soneChangeDetector = new SoneChangeDetector(
+ oldSone);
+ soneChangeDetector.onNewPosts(new PostProcessor() {
+ @Override
+ public void processPost(Post post) {
+ if (post.getSone().equals(newSone)) {
+ post.setKnown(true);
+ } else if (post.getTime() < database.getFollowingTime(newSone.getId())) {
+ post.setKnown(true);
+ } else if (!post.isKnown()) {
+ events.add(new NewPostFoundEvent(post));
+ }
+ }
+ });
+ soneChangeDetector.onRemovedPosts(new PostProcessor() {
+ @Override
+ public void processPost(Post post) {
+ events.add(new PostRemovedEvent(post));
+ }
+ });
+ soneChangeDetector.onNewPostReplies(new PostReplyProcessor() {
+ @Override
+ public void processPostReply(PostReply postReply) {
+ if (postReply.getSone().equals(newSone)) {
+ postReply.setKnown(true);
+ } else if (postReply.getTime() < database.getFollowingTime(newSone.getId())) {
+ postReply.setKnown(true);
+ } else if (!postReply.isKnown()) {
+ events.add(new NewPostReplyFoundEvent(postReply));
+ }
+ }
+ });
+ soneChangeDetector.onRemovedPostReplies(new PostReplyProcessor() {
+ @Override
+ public void processPostReply(PostReply postReply) {
+ events.add(new PostReplyRemovedEvent(postReply));
+ }
+ });
+ soneChangeDetector.detectChanges(newSone);
+ return events;
+ }
+