Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.75 KB | None | 0 0
  1. package nl.saxion.main.dataprovider;
  2.  
  3. import nl.saxion.main.models.Expansion;
  4. import nl.saxion.main.models.Game;
  5. import nl.saxion.main.models.Platform;
  6. import nl.saxion.main.models.User;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Objects;
  10.  
  11. public class DataProvider {
  12.     public ArrayList<Platform> platformList;
  13.     public ArrayList<User> userList;
  14.     private static DataProvider dataProvider;
  15.  
  16.     /**
  17.      * gives static instance of our data provider
  18.      *
  19.      * @return dataProvider
  20.      */
  21.     public static DataProvider getInstance() {
  22.  
  23.         if (dataProvider == null) {
  24.             dataProvider = new DataProvider();
  25.         }
  26.         return dataProvider;
  27.     }
  28.  
  29.     private DataProvider() {
  30.         this.platformList = new ArrayList<>();
  31.         userList = new ArrayList<>();
  32.  
  33.         init();
  34.     }
  35.  
  36.     private void init() {
  37.         User michael = new User("michael@saxion.nl", "1234");
  38.         this.userList.add(michael);
  39.         Platform ps4 = new Platform("Sony", "Playstation 4");
  40.         michael.addPlatform(ps4);
  41.         Game r6Siege = new Game("Rainbow six siege", "Fps");
  42.         ps4.addGame(r6Siege);
  43.         Platform xboxOne = new Platform("Microsoft", "Xbox One");
  44.         michael.addPlatform(xboxOne);
  45.  
  46.         User hidde = new User("hidde@saxion.nl", "0000");
  47.         this.userList.add(hidde);
  48.     }
  49.  
  50.     /**
  51.      * Adds user to userList
  52.      *
  53.      * @param user user
  54.      */
  55.     public void addUSer(User user) {
  56.         this.userList.add(user);
  57.     }
  58.  
  59.     /**
  60.      * Returns userList
  61.      *
  62.      * @return userList
  63.      */
  64.     public ArrayList<User> getUserList() {
  65.         return new ArrayList<>(userList);
  66.     }
  67.  
  68.     /**
  69.      * Adds platform to platformList
  70.      *
  71.      * @param platform platform
  72.      */
  73.     public void addPlatform(Platform platform) {
  74.         this.platformList.add(platform);
  75.     }
  76.  
  77.     /**
  78.      * Returns platformList
  79.      *
  80.      * @return platformList
  81.      */
  82.     public ArrayList<Platform> getPlatformList() {
  83.         return new ArrayList<>(platformList);
  84.     }
  85.  
  86.     /**
  87.      * Gets platform by UUID
  88.      *
  89.      * @param uuid uuid
  90.      * @return currentPlatform
  91.      */
  92.     public Platform getPlatformByUUID(String uuid) {
  93.  
  94.         for (User user : userList) {
  95.             for (Platform currentPlatform : user.getListOfPlatforms()) {
  96.                 if (currentPlatform.getUuid().equals(uuid)) {
  97.                     return currentPlatform;
  98.                 }
  99.             }
  100.         }
  101.         return null;
  102.     }
  103.  
  104.     /**
  105.      * Gets game by UUID
  106.      *
  107.      * @param uuid uuid
  108.      * @return currentGame
  109.      */
  110.     public Game getGameByUUID(String uuid) {
  111.         for (User user : userList) {
  112.             for (Platform platform : user.getListOfPlatforms()) {
  113.                 for (Game game : platform.getListOfGames()) {
  114.                     if (game.getUuid().equals(uuid)) {
  115.                         return game;
  116.                     }
  117.                 }
  118.             }
  119.         }
  120.         return null;
  121.     }
  122.  
  123.     /**
  124.      * Gets expansion by UUID
  125.      *
  126.      * @param uuid uuid
  127.      * @return currentExpansion
  128.      */
  129.     public Expansion getExpansionByUUID(String uuid) {
  130.         for (User user : userList){
  131.             for (Platform platform : user.getListOfPlatforms()) {
  132.                 for (Game game : platform.getListOfGames()) {
  133.                     for (Expansion expansion : game.getListOfExpansions()) {
  134.                         if (expansion.getUuid().equals(uuid)) {
  135.                             return expansion;
  136.                         }
  137.                     }
  138.                 }
  139.             }
  140.         }
  141.         return null;
  142.     }
  143.  
  144.     /**
  145.      * Updates the platform we want
  146.      *
  147.      * @param platform platform
  148.      */
  149.     public void updatePlatform(Platform platform) {
  150.         String uuid = platform.getUuid();
  151.         for (User user : userList) {
  152.             for (int i = 0; i < user.getListOfPlatforms().size(); i++) {
  153.                 if (user.getListOfPlatforms().get(i).getUuid().equals(uuid)) {
  154.                     user.getListOfPlatforms().set(i, platform);
  155.                 }
  156.             }
  157.         }
  158.     }
  159.  
  160.     /**
  161.      * Updates the game we want
  162.      *
  163.      * @param game game
  164.      */
  165.     public void updateGame(Game game) {
  166.         String uuid = game.getUuid();
  167.         for (User user : userList) {
  168.             for (Platform platform : user.getListOfPlatforms()) {
  169.                 for (int i = 0; i < platform.getListOfGames().size(); i++) {
  170.                     Game currentGame = platform.getListOfGames().get(i);
  171.                     if (currentGame.getUuid().equals(uuid)) {
  172.                         platform.getListOfGames().set(i, game);
  173.                     }
  174.                 }
  175.             }
  176.         }
  177.     }
  178.  
  179.     /**
  180.      * Updates the expansion we want
  181.      *
  182.      * @param expansion expansion
  183.      */
  184.     public void updateExpansion(Expansion expansion) {
  185.         String uuid = expansion.getUuid();
  186.         for (User user : userList) {
  187.             for (Platform platform : user.getListOfPlatforms()) {
  188.                 for (Game game : platform.getListOfGames()) {
  189.                     for (int i = 0; i < game.getListOfExpansions().size(); i++) {
  190.                         Expansion currentExpansion = game.getListOfExpansions().get(i);
  191.                         if (currentExpansion.getUuid().equals(uuid)) {
  192.                             game.getListOfExpansions().set(i, expansion);
  193.                         }
  194.                     }
  195.                 }
  196.             }
  197.         }
  198.     }
  199.  
  200.     /**
  201.      * Removes the platform we want
  202.      *
  203.      * @param platform platform
  204.      */
  205.     public void removePlatform(Platform platform) {
  206.         Platform platformToRemove = null;
  207.         String uuid = platform.getUuid();
  208.         for (User user : userList) {
  209.             for (Platform currentPlatform : user.getListOfPlatforms()) {
  210.                 if (currentPlatform.getUuid().equals(uuid)) {
  211.                     platformToRemove = currentPlatform;
  212.                 }
  213.             }
  214.             user.getListOfPlatforms().remove(platformToRemove);
  215.         }
  216.     }
  217.  
  218.     /**
  219.      * Removes the game we want
  220.      *
  221.      * @param game game
  222.      */
  223.     public void removeGame(Game game) {
  224.         Game gameToRemove = null;
  225.         Platform platformToRemoveFrom = null;
  226.         String uuid = game.getUuid();
  227.         for (User user : userList) {
  228.             for (Platform platform : user.getListOfPlatforms()) {
  229.                 for (Game currentGame : platform.getListOfGames()) {
  230.                     if (currentGame.getUuid().equals(uuid)) {
  231.                         gameToRemove = currentGame;
  232.                         platformToRemoveFrom = platform;
  233.                     }
  234.                 }
  235.             }
  236.             Objects.requireNonNull(platformToRemoveFrom).getListOfGames().remove(gameToRemove);
  237.         }
  238.     }
  239.  
  240.     /**
  241.      * Removes the expansion we want
  242.      *
  243.      * @param expansion expansion
  244.      */
  245.     public void removeExpansion(Expansion expansion) {
  246.         Expansion expansionToRemove = null;
  247.         Game gameToRemoveFrom = null;
  248.         String uuid = expansion.getUuid();
  249.         for (User user : userList) {
  250.             for (Platform platform : user.getListOfPlatforms()) {
  251.                 for (Game game : platform.getListOfGames()) {
  252.                     gameToRemoveFrom = game;
  253.                     for (Expansion currentExpansion : game.getListOfExpansions()) {
  254.                         if (currentExpansion.getUuid().equals(uuid)) {
  255.                             expansionToRemove = currentExpansion;
  256.                         }
  257.                     }
  258.                 }
  259.             }
  260.             Objects.requireNonNull(gameToRemoveFrom).getListOfExpansions().remove(expansionToRemove);
  261.         }
  262.     }
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement