+ allPostReplies.put(postReply.getId(), postReply);
+ if (postReplies.containsKey(postReply.getPostId())) {
+ postReplies.get(postReply.getPostId()).add(postReply);
+ } else {
+ TreeSet<PostReply> replies = new TreeSet<PostReply>(Reply.TIME_COMPARATOR);
+ replies.add(postReply);
+ postReplies.put(postReply.getPostId(), replies);
+ }
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ /** {@inheritDocs} */
+ @Override
+ public void storePostReplies(Sone sone, Collection<PostReply> postReplies) {
+ checkNotNull(sone, "sone must not be null");
+ /* verify that all posts are from the same Sone. */
+ for (PostReply postReply : postReplies) {
+ if (!sone.equals(postReply.getSone())) {
+ throw new IllegalArgumentException(String.format("PostReply from different Sone found: %s", postReply));
+ }
+ }
+
+ lock.writeLock().lock();
+ try {
+ /* remove all post replies of the Sone. */
+ for (PostReply postReply : getRepliesFrom(sone.getId())) {
+ removePostReply(postReply);
+ }
+ for (PostReply postReply : postReplies) {
+ allPostReplies.put(postReply.getId(), postReply);
+ sonePostReplies.put(postReply.getSone().getId(), postReply);
+ if (this.postReplies.containsKey(postReply.getPostId())) {
+ this.postReplies.get(postReply.getPostId()).add(postReply);
+ } else {
+ TreeSet<PostReply> replies = new TreeSet<PostReply>(Reply.TIME_COMPARATOR);
+ replies.add(postReply);
+ this.postReplies.put(postReply.getPostId(), replies);