User.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package analyzer.models;
  2. import java.util.*;
  3. import java.util.concurrent.atomic.AtomicInteger;
  4. import java.util.concurrent.atomic.AtomicReference;
  5. public class User {
  6. private final String id;
  7. private Map<Hashtag, Integer> hashtagMap;
  8. private Map<Round, Integer> roundMap;
  9. public User(String id) {
  10. this.id = id;
  11. hashtagMap = new Hashtable<>();
  12. roundMap = new Hashtable<>();
  13. }
  14. public String getId() {
  15. return this.id;
  16. }
  17. public Map<Hashtag, Integer> getHashtags() {
  18. return this.hashtagMap;
  19. }
  20. public void addHashtag(Hashtag hashtag) {
  21. Integer value = this.hashtagMap.get(hashtag);
  22. if (value != null)
  23. this.hashtagMap.replace(hashtag, value + 1);
  24. else
  25. this.hashtagMap.put(hashtag, 1);
  26. }
  27. public void addRound(Round round) {
  28. Integer value = this.roundMap.get(round);
  29. if (value != null)
  30. this.roundMap.replace(round, value + 1);
  31. else
  32. this.roundMap.put(round, 1);
  33. }
  34. public int totalPosts() {
  35. AtomicInteger n = new AtomicInteger();
  36. roundMap.forEach((k, v) -> n.set(n.get() + v));
  37. return n.get();
  38. }
  39. public Map<Round, Integer> getRounds() {
  40. return roundMap;
  41. }
  42. public String hashtagsToString() {
  43. AtomicReference<String> s = new AtomicReference<>("");
  44. hashtagMap.forEach((k, v) -> s.set(s + k.getName() + " "));
  45. return s.get().trim();
  46. }
  47. }