Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nl.saxion.main.dataprovider;
- import nl.saxion.main.models.Expansion;
- import nl.saxion.main.models.Game;
- import nl.saxion.main.models.Platform;
- import nl.saxion.main.models.User;
- import java.util.ArrayList;
- import java.util.Objects;
- public class DataProvider {
- public ArrayList<Platform> platformList;
- public ArrayList<User> userList;
- private static DataProvider dataProvider;
- /**
- * gives static instance of our data provider
- *
- * @return dataProvider
- */
- public static DataProvider getInstance() {
- if (dataProvider == null) {
- dataProvider = new DataProvider();
- }
- return dataProvider;
- }
- private DataProvider() {
- this.platformList = new ArrayList<>();
- userList = new ArrayList<>();
- init();
- }
- private void init() {
- User michael = new User("michael@saxion.nl", "1234");
- this.userList.add(michael);
- Platform ps4 = new Platform("Sony", "Playstation 4");
- michael.addPlatform(ps4);
- Game r6Siege = new Game("Rainbow six siege", "Fps");
- ps4.addGame(r6Siege);
- Platform xboxOne = new Platform("Microsoft", "Xbox One");
- michael.addPlatform(xboxOne);
- User hidde = new User("hidde@saxion.nl", "0000");
- this.userList.add(hidde);
- }
- /**
- * Adds user to userList
- *
- * @param user user
- */
- public void addUSer(User user) {
- this.userList.add(user);
- }
- /**
- * Returns userList
- *
- * @return userList
- */
- public ArrayList<User> getUserList() {
- return new ArrayList<>(userList);
- }
- /**
- * Adds platform to platformList
- *
- * @param platform platform
- */
- public void addPlatform(Platform platform) {
- this.platformList.add(platform);
- }
- /**
- * Returns platformList
- *
- * @return platformList
- */
- public ArrayList<Platform> getPlatformList() {
- return new ArrayList<>(platformList);
- }
- /**
- * Gets platform by UUID
- *
- * @param uuid uuid
- * @return currentPlatform
- */
- public Platform getPlatformByUUID(String uuid) {
- for (User user : userList) {
- for (Platform currentPlatform : user.getListOfPlatforms()) {
- if (currentPlatform.getUuid().equals(uuid)) {
- return currentPlatform;
- }
- }
- }
- return null;
- }
- /**
- * Gets game by UUID
- *
- * @param uuid uuid
- * @return currentGame
- */
- public Game getGameByUUID(String uuid) {
- for (User user : userList) {
- for (Platform platform : user.getListOfPlatforms()) {
- for (Game game : platform.getListOfGames()) {
- if (game.getUuid().equals(uuid)) {
- return game;
- }
- }
- }
- }
- return null;
- }
- /**
- * Gets expansion by UUID
- *
- * @param uuid uuid
- * @return currentExpansion
- */
- public Expansion getExpansionByUUID(String uuid) {
- for (User user : userList){
- for (Platform platform : user.getListOfPlatforms()) {
- for (Game game : platform.getListOfGames()) {
- for (Expansion expansion : game.getListOfExpansions()) {
- if (expansion.getUuid().equals(uuid)) {
- return expansion;
- }
- }
- }
- }
- }
- return null;
- }
- /**
- * Updates the platform we want
- *
- * @param platform platform
- */
- public void updatePlatform(Platform platform) {
- String uuid = platform.getUuid();
- for (User user : userList) {
- for (int i = 0; i < user.getListOfPlatforms().size(); i++) {
- if (user.getListOfPlatforms().get(i).getUuid().equals(uuid)) {
- user.getListOfPlatforms().set(i, platform);
- }
- }
- }
- }
- /**
- * Updates the game we want
- *
- * @param game game
- */
- public void updateGame(Game game) {
- String uuid = game.getUuid();
- for (User user : userList) {
- for (Platform platform : user.getListOfPlatforms()) {
- for (int i = 0; i < platform.getListOfGames().size(); i++) {
- Game currentGame = platform.getListOfGames().get(i);
- if (currentGame.getUuid().equals(uuid)) {
- platform.getListOfGames().set(i, game);
- }
- }
- }
- }
- }
- /**
- * Updates the expansion we want
- *
- * @param expansion expansion
- */
- public void updateExpansion(Expansion expansion) {
- String uuid = expansion.getUuid();
- for (User user : userList) {
- for (Platform platform : user.getListOfPlatforms()) {
- for (Game game : platform.getListOfGames()) {
- for (int i = 0; i < game.getListOfExpansions().size(); i++) {
- Expansion currentExpansion = game.getListOfExpansions().get(i);
- if (currentExpansion.getUuid().equals(uuid)) {
- game.getListOfExpansions().set(i, expansion);
- }
- }
- }
- }
- }
- }
- /**
- * Removes the platform we want
- *
- * @param platform platform
- */
- public void removePlatform(Platform platform) {
- Platform platformToRemove = null;
- String uuid = platform.getUuid();
- for (User user : userList) {
- for (Platform currentPlatform : user.getListOfPlatforms()) {
- if (currentPlatform.getUuid().equals(uuid)) {
- platformToRemove = currentPlatform;
- }
- }
- user.getListOfPlatforms().remove(platformToRemove);
- }
- }
- /**
- * Removes the game we want
- *
- * @param game game
- */
- public void removeGame(Game game) {
- Game gameToRemove = null;
- Platform platformToRemoveFrom = null;
- String uuid = game.getUuid();
- for (User user : userList) {
- for (Platform platform : user.getListOfPlatforms()) {
- for (Game currentGame : platform.getListOfGames()) {
- if (currentGame.getUuid().equals(uuid)) {
- gameToRemove = currentGame;
- platformToRemoveFrom = platform;
- }
- }
- }
- Objects.requireNonNull(platformToRemoveFrom).getListOfGames().remove(gameToRemove);
- }
- }
- /**
- * Removes the expansion we want
- *
- * @param expansion expansion
- */
- public void removeExpansion(Expansion expansion) {
- Expansion expansionToRemove = null;
- Game gameToRemoveFrom = null;
- String uuid = expansion.getUuid();
- for (User user : userList) {
- for (Platform platform : user.getListOfPlatforms()) {
- for (Game game : platform.getListOfGames()) {
- gameToRemoveFrom = game;
- for (Expansion currentExpansion : game.getListOfExpansions()) {
- if (currentExpansion.getUuid().equals(uuid)) {
- expansionToRemove = currentExpansion;
- }
- }
- }
- }
- Objects.requireNonNull(gameToRemoveFrom).getListOfExpansions().remove(expansionToRemove);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement