示例#1
0
 private boolean hasMatch(Collection<Game> existingGames, Team team) {
   for (Game game : existingGames) {
     if (game.getParticipants().contains(team)) {
       return true;
     }
   }
   return false;
 }
示例#2
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());
     }
   }
 }
示例#3
0
 public Map<Participant, Map<Game, String>> getParticipantGameResultMap(
     Collection<Game> games, Boolean reverseGameResult) {
   Map<Participant, Map<Game, String>> participantGameResultMap = new HashMap<>();
   for (Game game : games) {
     for (Participant p : game.getParticipants()) {
       Map<Game, String> gameResultMap = participantGameResultMap.get(p);
       if (gameResultMap == null) {
         gameResultMap = new HashMap<>();
       }
       String result = getGameResult(game, p, reverseGameResult);
       gameResultMap.put(game, result);
       participantGameResultMap.put(p, gameResultMap);
     }
   }
   return participantGameResultMap;
 }
示例#4
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;
 }
示例#5
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));
         }
       }
     }
   }
 }
示例#6
0
  public String getGameResult(
      Game game, final Participant sortByParticipant, final Boolean reverseGameResult) {
    StringBuilder result = new StringBuilder();

    List<GameSet> gameSets = new ArrayList<>(game.getGameSets());
    Collections.sort(gameSets);

    int gameSetsDisplayed = 0;
    for (int set = FIRST_SET; set < gameSets.size(); set++) {
      int participantId = 0;
      Set<Participant> participants = game.getParticipants();
      if (sortByParticipant != null) {
        SortedSet<Participant> sortedParticipants =
            new TreeSet<>(
                new ParticipantByGameResultComparator(sortByParticipant, reverseGameResult));
        sortedParticipants.addAll(participants);
        participants = sortedParticipants;
      }

      for (Participant participant : participants) {
        String setGames = "-";
        for (GameSet gs : gameSets) {
          if (gs.getSetNumber() == set && gs.getParticipant().equals(participant)) {
            setGames = gs.getSetGames() + "";
            gameSetsDisplayed++;
            break;
          }
        }
        result.append(setGames);
        result.append(participantId % 2 == 0 ? ":" : " "); // separate games by colon, sets by space
        participantId++;
      }
      if (gameSetsDisplayed == gameSets.size()) {
        break; // do not display third set if it was not played
      }
    }

    return result.toString();
  }