change method addPlace

start TournamentTest implementation
This commit is contained in:
Andrin Fassbind
2022-05-12 23:15:42 +02:00
parent f885092259
commit 68080c36ff
5 changed files with 108 additions and 13 deletions
@@ -29,4 +29,8 @@ public class Place implements Serializable {
public boolean equals(Place place){
return name.equals(place.getName());
}
public void change(Place place) {
//TODO: If Place gets more developt in future releases
}
}
@@ -2,6 +2,7 @@ package ch.zhaw.projekt2.turnierverwaltung;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import java.io.Serializable;
import java.util.*;
@@ -28,8 +29,8 @@ public class Tournament implements Serializable {
}
public void saveParticipant(Participant newParticipant) {
for(Participant participant: participants){
if(participant.equals(newParticipant)){
for (Participant participant : participants) {
if (participant.equals(newParticipant)) {
participant.change(newParticipant);
return;
}
@@ -50,8 +51,13 @@ public class Tournament implements Serializable {
return participantsObservable;
}
public void addPlace(Place newPlace) throws PlaceExistsException {
places.removeIf(place -> place.equals(newPlace));
public void addPlace(Place newPlace) {
for (Place place : places) {
if (place.equals(newPlace)) {
place.change(newPlace);
return;
}
}
places.add(newPlace);
}
@@ -91,7 +97,7 @@ public class Tournament implements Serializable {
private boolean numberOfParticipantValid() {
double res = Math.log(participants.size()) / Math.log(2);
return (res * 10) % 10 == 0 && participants.size() >=4;
return (res * 10) % 10 == 0 && participants.size() >= 4;
}
private void calcGameSchedule() {
@@ -101,11 +107,11 @@ public class Tournament implements Serializable {
List<Game> gameRound = new ArrayList<>();
if (i == 0) {
for (int j = 0; j < participants.size() - 1; j += 2) {
gameRound.add(new Game(participants.get(j), participants.get(j+1)));
gameRound.add(new Game(participants.get(j), participants.get(j + 1)));
}
} else {
for (int j = 0; j < (gameList.get(i-1).size()/2); j++) {
gameRound.add(new Game(gameList.get(i-1).get(j*2),gameList.get(i-1).get(j*2+1)));
for (int j = 0; j < (gameList.get(i - 1).size() / 2); j++) {
gameRound.add(new Game(gameList.get(i - 1).get(j * 2), gameList.get(i - 1).get(j * 2 + 1)));
}
}
gameList.add(gameRound);
@@ -148,10 +148,6 @@ public class TournamentDecorator implements IsObservable{
tournament.addPlace(new Place(name));
factoryDecorator.clearMessage(true);
informListener();
} catch (Tournament.PlaceExistsException e) {
e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Ort existiert bereits",true);
} catch (InvalidNameException e) {
e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Invalider Ortsname",true);