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 31300f5..844f941 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java @@ -6,5 +6,5 @@ public interface Participant extends Serializable { String getName(); void setName(String name); boolean equals(Participant participant); - void change(Participant participant); + void change(Participant participant) throws Person.InvalidPhoneNumberException; } 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 4171ae1..4fa62b8 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Person.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Person.java @@ -8,7 +8,7 @@ import java.util.logging.Logger; */ 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; @@ -29,16 +29,7 @@ public class Person implements Serializable { public Person(String firstName, String name, String phoneNumber) throws InvalidNameException, InvalidPhoneNumberException { logger.finer("Trying to initialize a new person with name: " + name + ", first name: " + firstName + ", Phone number: " + phoneNumber); - if (!firstName.matches(NAME_MATCHING_REGEX)) { - logger.warning("First name: " + firstName + ", is not in a valid format"); - throw new InvalidNameException("The First name is Invalid."); - } else if (!name.matches(NAME_MATCHING_REGEX)) { - logger.warning("Name: " + name + ", is not in a valid format"); - throw new InvalidNameException("The Last name is Invalid"); - } else if (!phoneNumber.matches(PHONE_MATCHING_REGEX)) { - logger.warning("Phone number: " + phoneNumber + ", is not in a valid format"); - throw new InvalidPhoneNumberException("The entered Phone Number is invalid."); - } + setFirstName(firstName); setName(name); setPhoneNumber(phoneNumber); @@ -61,7 +52,11 @@ public class Person implements Serializable { * * @param name of the person to be set */ - public void setName(String name) { + public void setName(String name) throws InvalidNameException { + if (!name.matches(NAME_MATCHING_REGEX)) { + logger.warning("Name: " + name + ", is not in a valid format"); + throw new InvalidNameException("The Last name is Invalid"); + } logger.fine("Setting new name of " + this + " with: " + name); this.name = name; } @@ -76,13 +71,18 @@ public class Person implements Serializable { * * @param firstName the person to be set */ - public void setFirstName(String firstName) { + public void setFirstName(String firstName) throws InvalidNameException { + if (!firstName.matches(NAME_MATCHING_REGEX)) { + logger.warning("First name: " + firstName + ", is not in a valid format"); + throw new InvalidNameException("The First name is Invalid."); + } logger.fine("Setting new first name of " + this + " with: " + firstName); this.firstName = firstName; } /** * Method used to get the Phone number of a Person + * * @return phone number of the person */ public String getPhoneNumber() { @@ -92,9 +92,14 @@ public class Person implements Serializable { /** * Method used to set the Phone number of a Person + * * @param phoneNumber to be set */ - public void setPhoneNumber(String phoneNumber) { + public void setPhoneNumber(String phoneNumber) throws InvalidPhoneNumberException { + if (!phoneNumber.matches(PHONE_MATCHING_REGEX)) { + logger.warning("Phone number: " + phoneNumber + ", is not in a valid format"); + throw new InvalidPhoneNumberException("The entered Phone Number is invalid."); + } logger.fine("Setting new phone number of " + this + " with: " + phoneNumber); this.phoneNumber = phoneNumber; } @@ -103,9 +108,6 @@ public class Person implements Serializable { * Exception, that is used when a Phone number is in an invalid format. */ public class InvalidPhoneNumberException extends Exception { - public InvalidPhoneNumberException() { - super(); - } public InvalidPhoneNumberException(String errorMessage) { super(errorMessage); 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 5d31099..de2a18c 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java @@ -79,7 +79,7 @@ public class Team implements Participant { /** * Override of equals Method to compare teams with each other * - * @param participant + * @param participant to be compared with this instance * @return true if teams are the same false if not. */ @Override @@ -87,10 +87,13 @@ public class Team implements Participant { return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase()); } - //TODO ??? + /** + * Functionality to save a team is not implemented in this prototype, so no functionality is set yet to change the team + * + * @param participant date object containing new data + */ @Override public void change(Participant participant) { - return; } /** 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 fec9af8..f2a6e7b 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 @@ -74,7 +74,7 @@ public class ParticipantFormularController extends FXController { participantNameTextField.setText(participant.getName()); firstNameTextField.setText(participant.getFirstName()); phoneNumberTextField.setText(participant.getPhoneNumber()); - birthDateTextField.setText(participant.getFormatedDateOfBirth()); + birthDateTextField.setText(participant.getFormattedDateOfBirth()); } @FXML