Graph database Analysis of the Steam Network
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.0 KiB

  1. package net.jrtechs.www.model;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Map;
  5. /**
  6. * Class to store information on a player
  7. *
  8. * @author Jeffery Russell 5-26-18
  9. */
  10. public class Player
  11. {
  12. public static String KEY_STEAM_ID = "steamid";
  13. public static String KEY_REAL_NAME = "realname";
  14. public static String KEY_TIME_CREATED = "timecreated";
  15. public static String KEY_AVATAR = "avatarfull";
  16. public static String KEY_USERNAME = "personaname";
  17. public static String KEY_FRIENDS = "friends";
  18. /** Name of the player **/
  19. private String name;
  20. /** Steam id of the player **/
  21. private String id;
  22. /** List of friends the player has */
  23. private List<Player> friends;
  24. private String realName;
  25. private String avatar;
  26. private Integer timeCreated;
  27. private List<Game> playerGames;
  28. /**
  29. * Sets the name and id of the player
  30. *
  31. * @param name
  32. * @param id
  33. */
  34. public Player(String name, String id,
  35. String realName, Integer timeCreated,
  36. String avatar)
  37. {
  38. this.name = name;
  39. this.id = id;
  40. this.realName = realName;
  41. this.timeCreated = timeCreated;
  42. this.avatar = avatar;
  43. this.friends = new ArrayList<>();
  44. this.playerGames = new ArrayList<>();
  45. }
  46. public Player(Map<String, Object> apiInfo)
  47. {
  48. this.id = ((List<Object>) apiInfo.get(Player.KEY_STEAM_ID)).get(0).toString();
  49. this.name = ((List<Object>) apiInfo.get(Player.KEY_USERNAME)).get(0).toString();
  50. this.realName = ((List<Object>) apiInfo.getOrDefault(Player.KEY_REAL_NAME, "")).get(0).toString();
  51. this.avatar = ((List<Object>) apiInfo.getOrDefault(Player.KEY_AVATAR, "")).get(0).toString();
  52. this.timeCreated = (Integer)((List<Object>)apiInfo.get(KEY_TIME_CREATED)).get(0);
  53. this.friends = new ArrayList<>();
  54. this.playerGames = new ArrayList<>();
  55. }
  56. public List<Player> getFriends()
  57. {
  58. return friends;
  59. }
  60. public List<Game> getGames()
  61. {
  62. return this.playerGames;
  63. }
  64. /**
  65. * Getter for display name of player
  66. *
  67. * @return
  68. */
  69. public String getName()
  70. {
  71. return this.name.replace("'", "");
  72. }
  73. /**
  74. * Getter for id of player
  75. *
  76. * @return
  77. */
  78. public String getId()
  79. {
  80. return this.id;
  81. }
  82. public void setFriends(List<Player> friends)
  83. {
  84. this.friends = friends;
  85. }
  86. public String getRealName()
  87. {
  88. return this.realName;
  89. }
  90. public String getAvatar()
  91. {
  92. return this.avatar;
  93. }
  94. public Integer getTimeCreated()
  95. {
  96. return this.timeCreated;
  97. }
  98. @Override
  99. public String toString()
  100. {
  101. return "Name: " + this.name +
  102. " id: " + this.id +
  103. " friend count " + friends.size() +
  104. " avatar:" + this.avatar +
  105. " real name " + this.realName +
  106. " created " + this.timeCreated;
  107. }
  108. }