From 3d13dbcb453decf8540699d8d8ff41168888d0df Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sat, 7 May 2022 11:53:10 +0200 Subject: [PATCH] changed ParticipantFormular to change existing objects and don't replace them. changed ParticipantFormular and PlacesFormular to clear textfields after saving. solved #19 --- .../turnierverwaltung/Participant.java | 1 + .../projekt2/turnierverwaltung/Person.java | 2 +- .../projekt2/turnierverwaltung/Player.java | 19 +++++++++++++++++-- .../zhaw/projekt2/turnierverwaltung/Team.java | 13 +++++++++++++ .../turnierverwaltung/Tournament.java | 9 +++++++-- .../TournamentDecorator.java | 3 +-- .../ParticipantFormularController.java | 8 ++++++++ .../PlacesFormularController.java | 5 +++++ 8 files changed, 53 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java index 6f85290..31300f5 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java @@ -6,4 +6,5 @@ public interface Participant extends Serializable { String getName(); void setName(String name); boolean equals(Participant participant); + void change(Participant participant); } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Person.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Person.java index 9cf624f..73e598b 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Person.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Person.java @@ -4,7 +4,7 @@ import java.io.Serializable; public class Person implements Serializable { 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 firstName; diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java index 3165364..29bb2c6 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java @@ -29,12 +29,27 @@ public class Player extends Person implements Participant{ } public void setDateOfBirth(String dateOfBirth) { - String[] date = dateOfBirth.split("\\."); - this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0])); + if(dateOfBirth.length() > 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 public boolean equals(Participant participant) { 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()); + } } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java index e815a16..8a2a0ba 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java @@ -27,11 +27,24 @@ public class Team implements Participant { this.name = name; } + public void setPlayers(List players) { + this.players = players; + } + + public List getPlayers() { + return players; + } + @Override public boolean equals(Participant participant) { return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase()); } + @Override + public void change(Participant participant) { + return; + } + public Person getContactPerson() { return contactPerson; } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java index b4097d5..21c9a5e 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -31,8 +31,13 @@ public class Tournament implements Serializable { places = new ArrayList<>(); } - public void addParticipant(Participant newParticipant) throws ParticipantExistsException { - participants.removeIf(participant -> participant.equals(newParticipant)); + public void saveParticipant(Participant newParticipant) throws ParticipantExistsException { + for(Participant participant: participants){ + if(participant.equals(newParticipant)){ + participant.change(newParticipant); + return; + } + } participants.add(newParticipant); } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java index dcb3112..6f28efd 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java @@ -2,7 +2,6 @@ package ch.zhaw.projekt2.turnierverwaltung; import java.io.IOException; import java.util.ArrayList; -import java.util.Date; import java.util.List; 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){ try { - tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth)); + tournament.saveParticipant(new Player(firstName, name, phoneNumber, dateOfBirth)); informListener(); } catch (Tournament.ParticipantExistsException e) { e.printStackTrace(); //TODO handle and logging diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java index 0528301..8492fdd 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java @@ -79,6 +79,14 @@ public class ParticipantFormularController extends FXController { @FXML void saveParticipant(ActionEvent event) { getTournamentDecorator().savePlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText()); + clearFormular(); + } + + private void clearFormular() { + firstNameTextField.clear(); + participantNameTextField.clear(); + phoneNumberTextField.clear(); + birthDateTextField.clear(); } @FXML diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java index c5534e5..036fb4f 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/placesAddFormular/PlacesFormularController.java @@ -58,6 +58,11 @@ public class PlacesFormularController extends FXController { @FXML void savePlace(ActionEvent event) { getTournamentDecorator().savePlace(placeNameTextField.getText()); + clearFormular(); + } + + private void clearFormular() { + placeNameTextField.clear(); } @FXML