Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.github.jreddit.retrieval;
  
  import java.util.List;
  
 
 public class ExtendedComments {
 
 	private Comments comments;
 
 	public ExtendedComments(Comments comments) {
 		this. = comments;
 	}

    
Get the comment list from a given submission (ID36). The result is maximum amount_first_depth * RedditConstants.MAX_LIMIT_COMMENTS Which can be quite alot (e.g. 500x500 = 250000 comments)

Parameters:
user (Optional, set null if not used) The user as whom to retrieve the comments
submissionId Submission ID36 identifier
sort (Optional, set null if not used) CommentSort enum indicating the type of sorting to be applied (e.g. HOT, NEW, TOP, etc)
amount_first_depth (Optional, set -1 if not used) Integer representing the amount of first depth comments to retrieve
after (Optional, set to null if not used) After which comment to retrieve
Returns:
Comments for an article.
 
     public List<CommentofSubmission(String submissionIdCommentSort sortint amount_first_depthComment after) {
     	
     	if (amount_first_depth < -1) {
     		throw new IllegalArgumentException("A negative amount of comments is not allowed.");
     	}
     	
     	int limit = amount_first_depth > . ? . : amount_first_depth;
     	
     	// List of first depth comments
         List<Commentresult = .ofSubmission(submissionIdnull, -1, 1, limitsort);
 
         // Retrieval the deeper comments for each first depth comment
         for (Comment c : result) {
 
         	// If there is one reply at least
         	if (c.hasRepliesSomewhere()) {
 
         		// Deeper comments, more than 500 if extremely rare.
         		List<Commentsubresult = .ofSubmission(submissionIdc.getIdentifier(), -1, 8, .sort);
         		
         		//System.out.println(subresult.size());
         		c.setReplies(subresult.get(0).getReplies());
         	 	
         	}
 
         }
 
 		return result;
     	
     }

    
Get the comment list of the given user (username).

Parameters:
user (Optional, set null if not used) The user as whom to retrieve the comments
username Username of the user you want to retrieve from.
sort (Optional, set null if not used) Sorting method.
time (Optional, set null is not used) Time window
amount (Optional, set -1 if not used) Integer representing the desired amount of comments to return
after (Optional, set null if not used) After which comment to retrieve
Returns:
Comments of a user.
 
     public List<CommentofUser(String usernameUserOverviewSort sortTimeSpan timeint amountComment after) {
     	
     	if (amount < 0) {
     		throw new IllegalArgumentException("A negative amount of comments is not allowed.");
     	}
 
     	// List of comments
         List<Commentresult = new LinkedList<Comment>();
 
         // Do all iterations
         int counter = 0;
 		while (amount >= 0) {
 			
 			// Determine how much still to retrieve in this iteration
 			int limit = (amount < .) ? amount : .;
 			amount -= limit;
 			
 			// Retrieve comments
 			List<Commentsubresult = .ofUser(usernamesorttimecounterlimitafternulltrue);
 			if (subresult == null) {
 				return new ArrayList<Comment>();
 			}
 			result.addAll(subresult);
 			
			// Increment counter
			counter += limit;
			// If the end of the comment stream has been reached
			if (subresult.size() != limit) {
				//System.out.println("API Stream finished prematurely: received " + subresult.size() + " but wanted " + limit + ".");
				break;
			}
			// If nothing is left desired, exit.
			if (amount <= 0) {
				break;
			}
			// Previous last comment
			after = subresult.get(subresult.size() - 1);
		}
		return result;
    	
    }
    
New to GrepCode? Check out our FAQ X