Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
HowToKB/src/kb/howtokb/usecase/Comment.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
58 lines (53 sloc)
1.41 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kb.howtokb.usecase; | |
import org.json.simple.JSONObject; | |
public class Comment { | |
private String author; | |
private String comment; | |
private int likeCount; | |
private int replyCount; | |
public Comment(String author, String comment, int likeCount, int replyCount) { | |
super(); | |
this.author = author; | |
this.comment = comment; | |
this.likeCount = likeCount; | |
this.replyCount = replyCount; | |
} | |
public Comment(String author, String comment) { | |
super(); | |
this.author = author; | |
this.comment = comment; | |
} | |
@Override | |
public String toString() { | |
return "Comment:\nauthor=" + author + "\ncomment=" + comment + "\nlikeCount=" + likeCount + "\nreplyCount=" | |
+ replyCount + "\n"; | |
} | |
@SuppressWarnings("unchecked") | |
public JSONObject toJson(){ | |
JSONObject obj = new JSONObject(); | |
obj.put("author", getAuthor()); | |
obj.put("comment", getComment()); | |
obj.put("like", getLikeCount()); | |
obj.put("reply", getReplyCount()); | |
return obj; | |
} | |
public static Comment toComment(JSONObject obj){ | |
String author = (String) obj.get("author"); | |
String comment = (String) obj.get("comment"); | |
int like = (int) (long) obj.get("like"); | |
int reply = (int) (long) obj.get("reply"); | |
return new Comment(author, comment, like, reply); | |
} | |
public String getAuthor() { | |
return author; | |
} | |
public String getComment() { | |
return comment; | |
} | |
public int getLikeCount() { | |
return likeCount; | |
} | |
public int getReplyCount() { | |
return replyCount; | |
} | |
} |