Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public class RetweetsIdRoute implements Route {
  2.  
  3. @Override
  4. public Object handle(Request request, Response response) throws Exception {
  5. final String idParam = request.params(":id");
  6. final String count = request.queryParams("count");
  7.  
  8. return fetchTweets(
  9. Long.valueOf(idParam),
  10. Integer.valueOf(count != null && count.length() > 0 ? count : "100")
  11. );
  12. }
  13.  
  14. private List<Tweet> fetchTweets(long id, int count) {
  15. return IntStream.range(0, 99)
  16. .mapToObj((i) -> {
  17. final Tweet tweet = new Tweet();
  18. tweet.id = id + i;
  19. tweet.text = String.format("Retweet #%s of %s for %s", i, count, id);
  20. tweet.favorited = i % 2 == 0;
  21.  
  22. return tweet;
  23. })
  24. .collect(Collectors.toList());
  25. }
  26.  
  27. public static Route create() {
  28. return new RetweetsIdRoute();
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement