示例#1
0
 public boolean equalsComment(Comment c) {
   if (c.getCommenter().equals(commenter)) {
     if (c.getComment().equals(comment)) {
       if (c.getDate().equals(date)) {
         return true;
       }
     }
   }
   return false;
 }
  private static final void printPostsAndComments(Blog blog) {
    UUID blogId = blog.getId();
    int maxPageToPrint = 3;
    int pageSize = 2; // 2 posts per page
    System.out.println("###################################################");
    System.out.println(blog.getBlogName().toUpperCase() + ":: by " + blog.getAuthor());
    System.out.println("###################################################");
    System.out.println("");

    try (SessionWrapper sessionWrapper = new SessionWrapper()) {
      UUID lastPostId = null;
      for (int i = 1; i <= maxPageToPrint; i++) {
        List<Post> posts = Post.getPosts(blogId, lastPostId, pageSize, sessionWrapper);
        for (Post post : posts) {
          System.out.println(
              post.getTitle().toUpperCase() + "\t" + "" + new Date(post.getPostedOn()).toString());
          PostVotes pvotes = new PostVotes().get(sessionWrapper, post.getId());
          System.out.println("Votes: +" + pvotes.getUpvotes() + "/-" + pvotes.getDownvotes());
          System.out.println("--------------------------------------------");
          System.out.println(post.getContent());
          System.out.println("Tags: " + post.getTags().toString());

          System.out.println("### COMMENTS:\n");

          List<Comment> comments = Comment.getComments(post.getId(), sessionWrapper);
          for (Comment comment : comments) {
            System.out.println("  >> " + comment.getTitle().toUpperCase());
            System.out.println("  " + comment.getContent());
            System.out.println(
                "   -- "
                    + comment.getCommenter()
                    + " on "
                    + new Date(comment.getPostedOn()).toString());
            CommentVotes cvotes = new CommentVotes().get(sessionWrapper, comment.getId());
            System.out.println("  Votes: +" + cvotes.getUpvotes() + "/-" + cvotes.getDownvotes());
            System.out.println("  -.-.-.-.-.-.-");
          }
          System.out.println();
          System.out.println("============================================");
          System.out.println();
        }
        System.out.println("END OF PAGE: " + i);
        System.out.println();
        System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        System.out.println();
      }
    }
  }