Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.github.jreddit.entity;
  
  import static com.github.jreddit.utils.restclient.JsonUtils.safeJsonToInteger;
  import static com.github.jreddit.utils.restclient.JsonUtils.safeJsonToString;
  import static com.github.jreddit.utils.restclient.JsonUtils.safeJsonToBoolean;
  import static com.github.jreddit.utils.restclient.JsonUtils.safeJsonToDouble;
  
  import java.util.List;
 
A Reddit comment. Contains the edited timestamp, the body

Author(s):
Benjamin Jakobus
Raul Rene Lepsa
Simon Kassing
 
 public class Comment extends Thing {
 
     private String author;			// Username of the author
     private String parentId;		// Parent identifier
     private String subreddit;		// Subreddit name
     private String subredditId;		// Subreddit identifier
     private String linkId;			// Submission (aka. link) identifier
     private String bodyHTML;		// The body with HTML markup
     private Boolean scoreHidden;	// Whether the score is hidden
     private String body;            // The actual body
     private Boolean edited;         // Edited timestamp
     private double created;         // Created timestamp
     private double createdUTC;      // Created UTC timestamp
     private Boolean hasReplies;		// If replies exist on reddit
     private List<Commentreplies;  // Replies if retrieved
     private Integer gilded;        	// Amount of times the comment been gilded
     private Integer score;        	// Karma score
     private Integer upvotes;        // Number of upvotes that this body received
     private Integer downvotes;      // Number of downvotes that this body received
     
     // Possible fields to add as well:
 //    private String bannedBy;
 //    String likes;
 //    private String approvedBy;
 //    private String authorFlairCSSClass;
 //    private String authorFlairText;
 //    String num_reports = null;
 //    String distinguished = null;
 
     public Comment(JSONObject obj) {
     	super(safeJsonToString(obj.get("name")));
     	
         try {
         	
             this.setAuthor(safeJsonToString(obj.get("author")));
             this.setParentId(safeJsonToString(obj.get("parent_id")));
             this.setBody(safeJsonToString(obj.get("body")));
             this.setEdited(safeJsonToBoolean(obj.get("edited")));
             this.setCreated(safeJsonToDouble(obj.get("created")));
             this.setCreatedUTC(safeJsonToDouble(obj.get("created_utc")));
              = (obj.get("replies") != null) ? !safeJsonToString(obj.get("replies")).isEmpty() : false;
             this. = new LinkedList<Comment>();
             this.setGilded(safeJsonToInteger(obj.get("gilded")));
             this.setScore(safeJsonToInteger(obj.get("score")));
             this.setUpvotes(safeJsonToInteger(obj.get("ups")));
             this.setDownvotes(safeJsonToInteger(obj.get("downs")));
             this.setSubreddit(safeJsonToString(obj.get("subreddit")));
             this.setSubredditId(safeJsonToString(obj.get("subreddit_id")));
             this.setLinkId(safeJsonToString(obj.get("link_id")));
             this.setBodyHTML(safeJsonToString(obj.get("body_html")));
             this.setScoreHidden(safeJsonToBoolean(obj.get("score_hidden")));
             
         } catch (Exception e) {
         	e.printStackTrace();
         	throw new IllegalArgumentException("JSON Object could not be parsed into a Comment. Provide a JSON Object with a valid structure.");
         }
 
     }
    
    
Add a reply to this comment.

Parameters:
c Reply comment
 
     public void addReply(Comment c) {
     	this..add(c);
     }
    
    
If the comment is retrieved recursively, this might have the replies.

Returns:
Replies
 
     public List<CommentgetReplies() {
     	return this.;
     }
     
     public void setReplies(List<Commentreplies) {
     	this. = replies;
     }
    
    
Return whether the comment has replies, this is only set if the comment is retrieved recursively.

Returns:
Whether there are replies on Reddit for this comment
    public Boolean hasRepliesSomewhere() {
    	return ;
    }
    public String getAuthor() {
        return ;
    }
    public void setAuthor(String author) {
        this. = author;
    }
    public String getParentId() {
        return ;
    }
    public void setParentId(String parentId) {
        this. = parentId;
    }
    public String getBody() {
        return ;
    }
    public void setBody(String body) {
        this. = body;
    }
    public Boolean getEdited() {
        return ;
    }
    public void setEdited(Boolean edited) {
        this. = edited;
    }
    public double getCreated() {
        return ;
    }
    public void setCreated(double created) {
        this. = created;
    }
    public Integer getGilded() {
		return ;
	}
	public void setGilded(Integer gilded) {
		this. = gilded;
	}
	public Integer getUpvotes() {
        return ;
    }
    public void setUpvotes(Integer upvotes) {
        this. = upvotes;
    }
    public Integer getDownvotes() {
        return ;
    }
    public void setDownvotes(Integer downvotes) {
        this. = downvotes;
    }
    
    public double getCreatedUTC() {
		return ;
	}
	public void setCreatedUTC(double createdUTC) {
		this. = createdUTC;
	}
	public Integer getScore() {
		return ;
	}
	public void setScore(Integer score) {
		this. = score;
	}

Returns:
the subreddit
	public String getSubreddit() {
		return ;
	}

Parameters:
subreddit the subreddit to set
	public void setSubreddit(String subreddit) {
		this. = subreddit;
	}

Returns:
the subredditId
	public String getSubredditId() {
		return ;
	}

Parameters:
subredditId the subredditId to set
	public void setSubredditId(String subredditId) {
		this. = subredditId;
	}

Returns:
the linkId
	public String getLinkId() {
		return ;
	}

Parameters:
linkId the linkId to set
	public void setLinkId(String linkId) {
		this. = linkId;
	}

Returns:
the bodyHTML
	public String getBodyHTML() {
		return ;
	}

Parameters:
bodyHTML the bodyHTML to set
	public void setBodyHTML(String bodyHTML) {
		this. = bodyHTML;
	}

Returns:
the scoreHidden
	public Boolean isScoreHidden() {
		return ;
	}

Parameters:
scoreHidden the scoreHidden to set
	public void setScoreHidden(Boolean scoreHidden) {
		this. = scoreHidden;
	}
    public String toString() {
    	return "Comment(" +  + ")<" + ((.length() > 10) ? .substring(0, 10) : ) + ">";
    }    
    
    @Override
    public boolean equals(Object other) {
    	return (other instanceof Comment && this.getFullName().equals(((Commentother).getFullName()));
    }
	public int compareTo(Thing o) {
		return this.getFullName().compareTo(o.getFullName());
	}
    
New to GrepCode? Check out our FAQ X