예제 #1
0
 private Set<Match> getAllMatchs() {
   Set<Match> matchs = new HashSet<Match>();
   for (Competition competition : this.competitions) {
     if (competition.getMatchs() != null) {
       matchs.addAll(competition.getMatchs());
     }
   }
   return matchs;
 }
예제 #2
0
 private Integer getLastCorrectCompetitionId() {
   Integer id = 0;
   for (Competition competition : this.competitions) {
     if (competition.getId() > id) {
       id = competition.getId();
     }
   }
   id++;
   return id;
 }
예제 #3
0
 @Override
 public Competition findCompetition(Competition competition) {
   Competition result = null;
   for (Competition competitionIt : this.competitions) {
     if (competitionIt.equals(competition)) {
       result = competitionIt;
     }
   }
   return result;
 }
예제 #4
0
 public void addCompetition(Competition competition) {
   if (competition.getId() == null) {
     Integer id = this.getLastCorrectCompetitionId();
     competition.setId(id);
   }
   if (competition.getMatchs() != null) {
     this.setIdsToMatchs(competition);
   }
   boolean insertCorrectly = this.competitions.add(competition);
   if (insertCorrectly == false) {
     throw new CompetitionInsertException("La competition no se ha insertado porque ya exisitia");
   }
 }
예제 #5
0
 private void setIdsToMatchs(Competition competition) {
   Integer idMatch = this.getLastCorrectMatchId();
   for (Match match : competition.getMatchs()) {
     if (match.getId() == null) {
       match.setId(idMatch);
       idMatch++;
     }
   }
 }