Skip to content
Permalink
0d82ff1dc4
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
58 lines (53 sloc) 1.41 KB
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;
}
}