changed ParticipantFormular to change existing objects and don't repl… #22

Merged
schrom01 merged 1 commits from fix_participanFormular_and_placesFormular into main 2022-05-12 11:39:16 +02:00
8 changed files with 53 additions and 7 deletions
Showing only changes of commit 3d13dbcb45 - Show all commits

View File

@ -6,4 +6,5 @@ public interface Participant extends Serializable {
String getName(); String getName();
void setName(String name); void setName(String name);
boolean equals(Participant participant); boolean equals(Participant participant);
void change(Participant participant);
} }

View File

@ -4,7 +4,7 @@ import java.io.Serializable;
public class Person implements Serializable { public class Person implements Serializable {
private final String NAME_MATCHING_REGEX = "[a-zA-Z]{1,20}"; private final String NAME_MATCHING_REGEX = "[a-zA-Z]{1,20}";
private final String PHONE_MATCHING_REGEX = "[\\+0-9]+"; private final String PHONE_MATCHING_REGEX = "[\\+]?[0-9]*";
private String name; private String name;
private String firstName; private String firstName;

View File

@ -29,12 +29,27 @@ public class Player extends Person implements Participant{
} }
public void setDateOfBirth(String dateOfBirth) { public void setDateOfBirth(String dateOfBirth) {
String[] date = dateOfBirth.split("\\."); if(dateOfBirth.length() > 0) {
this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0])); String[] date = dateOfBirth.split("\\.");
this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0]));
} else {
dateOfBirth = null;
}
}
public void setDateOfBirth(LocalDate dateOfBirth) {
this.dateOfBirth = dateOfBirth;
} }
@Override @Override
public boolean equals(Participant participant) { public boolean equals(Participant participant) {
return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase()); return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase());
} }
@Override
public void change(Participant participant) {
Player player = (Player) participant;
setDateOfBirth(player.getDateOfBirth());
setPhoneNumber(player.getPhoneNumber());
}
} }

View File

@ -27,11 +27,24 @@ public class Team implements Participant {
this.name = name; this.name = name;
} }
public void setPlayers(List<Player> players) {
this.players = players;
}
public List<Player> getPlayers() {
return players;
}
@Override @Override
public boolean equals(Participant participant) { public boolean equals(Participant participant) {
return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase()); return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase());
} }
@Override
public void change(Participant participant) {
return;
}
public Person getContactPerson() { public Person getContactPerson() {
return contactPerson; return contactPerson;
} }

View File

@ -31,8 +31,13 @@ public class Tournament implements Serializable {
places = new ArrayList<>(); places = new ArrayList<>();
} }
public void addParticipant(Participant newParticipant) throws ParticipantExistsException { public void saveParticipant(Participant newParticipant) throws ParticipantExistsException {
participants.removeIf(participant -> participant.equals(newParticipant)); for(Participant participant: participants){
if(participant.equals(newParticipant)){
participant.change(newParticipant);
return;
}
}
participants.add(newParticipant); participants.add(newParticipant);
} }

View File

@ -2,7 +2,6 @@ package ch.zhaw.projekt2.turnierverwaltung;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
public class TournamentDecorator implements IsObservable{ public class TournamentDecorator implements IsObservable{
@ -81,7 +80,7 @@ public class TournamentDecorator implements IsObservable{
public void savePlayer(String firstName, String name, String phoneNumber, String dateOfBirth){ public void savePlayer(String firstName, String name, String phoneNumber, String dateOfBirth){
try { try {
tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth)); tournament.saveParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
informListener(); informListener();
} catch (Tournament.ParticipantExistsException e) { } catch (Tournament.ParticipantExistsException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging

View File

@ -79,6 +79,14 @@ public class ParticipantFormularController extends FXController {
@FXML @FXML
void saveParticipant(ActionEvent event) { void saveParticipant(ActionEvent event) {
getTournamentDecorator().savePlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText()); getTournamentDecorator().savePlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText());
clearFormular();
}
private void clearFormular() {
firstNameTextField.clear();
participantNameTextField.clear();
phoneNumberTextField.clear();
birthDateTextField.clear();
} }
@FXML @FXML

View File

@ -58,6 +58,11 @@ public class PlacesFormularController extends FXController {
@FXML @FXML
void savePlace(ActionEvent event) { void savePlace(ActionEvent event) {
getTournamentDecorator().savePlace(placeNameTextField.getText()); getTournamentDecorator().savePlace(placeNameTextField.getText());
clearFormular();
}
private void clearFormular() {
placeNameTextField.clear();
} }
@FXML @FXML