Client.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 Client {
  6. private String id;
  7. private Map<Round, Integer> roundMap;
  8. private Group group;
  9. public Client(String id) {
  10. this.id = id;
  11. roundMap = new Hashtable<>();
  12. }
  13. public String getId() {
  14. return this.id;
  15. }
  16. public int getTotalPosts() {
  17. AtomicInteger result = new AtomicInteger();
  18. roundMap.forEach((round, integer) -> result.addAndGet(integer));
  19. return result.get();
  20. }
  21. public Map<Round, Integer> getRounds() {
  22. return this.roundMap;
  23. }
  24. public void addRound(Round round) {
  25. Integer value = this.roundMap.get(round);
  26. if (value != null)
  27. this.roundMap.replace(round, value + 1);
  28. else
  29. this.roundMap.put(round, 1);
  30. }
  31. public void setGroup(Group group) {
  32. this.group = group;
  33. }
  34. public Group getGroup() {
  35. return this.group;
  36. }
  37. public String getRoundtoString() {
  38. AtomicReference<String> s = new AtomicReference<>("");
  39. roundMap.forEach((k, v) -> s.set(s.get() + k.getNo() + " "));
  40. return s.get().trim();
  41. }
  42. public String postingTraces() {
  43. String s = "";
  44. List<Round> list = new ArrayList<>(roundMap.keySet());
  45. list.sort(Comparator.comparingInt(Round::getNo));
  46. for(Round r : list) {
  47. s += r.getNo() + ":" + roundMap.get(r) + " ";
  48. }
  49. return s.trim();
  50. }
  51. }