Example #1
0
 public void removeObsoleteGames(Event event, Set<? extends ParticipantI> newParticipants) {
   List<Game> eventGames = gameDAO.findByEvent(event);
   Iterator<Game> eventGameIterator = eventGames.iterator();
   while (eventGameIterator.hasNext()) {
     Game game = eventGameIterator.next();
     // only remove if game participant no longer participates in event
     if (!newParticipants.containsAll(game.getParticipants())) {
       eventGameIterator.remove();
       gameDAO.deleteById(game.getId());
     }
   }
 }
Example #2
0
 public void createMissingPullGames(Event event, Set<Team> participants) {
   List<Game> existingGames = gameDAO.findByEvent(event);
   for (Team team1 : participants) {
     for (Team team2 : participants) {
       if (!team1.equals(team2)) {
         if (!hasMatch(existingGames, team1) && !hasMatch(existingGames, team2)) {
           // make sure that players are distinct
           if (Sets.intersection(team1.getPlayers(), team2.getPlayers()).isEmpty()) {
             existingGames.add(createGame(event, team1, team2, null));
           }
         }
       }
     }
   }
 }
Example #3
0
 private Game createGame(
     Event event,
     Participant firstParticipant,
     Participant secondParticipant,
     Integer groupNumber) {
   Game game = new Game();
   game.setEvent(event);
   if (groupNumber != null) {
     game.setGroupNumber(groupNumber);
   }
   Set<Participant> gameParticipants = new LinkedHashSet<>();
   gameParticipants.add(firstParticipant);
   gameParticipants.add(secondParticipant);
   game.setParticipants(gameParticipants);
   game = gameDAO.saveOrUpdate(game);
   return game;
 }
Example #4
0
 public void createMissingGames(Event event, Set<Participant> participants, Integer groupNumber) {
   List<Game> existingGames = gameDAO.findByEvent(event);
   for (Participant firstParticipant : participants) {
     for (Participant secondParticipant : participants) {
       if (!firstParticipant.equals(secondParticipant)) {
         boolean gameExists = false;
         for (Game game : existingGames) {
           if (game.getParticipants().contains(firstParticipant)
               && game.getParticipants().contains(secondParticipant)) {
             gameExists = true;
             break;
           }
         }
         if (!gameExists) {
           existingGames.add(createGame(event, firstParticipant, secondParticipant, groupNumber));
         }
       }
     }
   }
 }