From 072db996dc9994f149345c57e12719b579a48e8a Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 13 May 2022 00:02:31 +0200 Subject: [PATCH 1/8] Added Java Doc and Logger to Team --- .../zhaw/projekt2/turnierverwaltung/Team.java | 71 ++++++++++++++++++- 1 file changed, 68 insertions(+), 3 deletions(-) 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 8a2a0ba..5d31099 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java @@ -2,59 +2,124 @@ package ch.zhaw.projekt2.turnierverwaltung; import java.util.ArrayList; import java.util.List; +import java.util.logging.Logger; + +/** + * Class Team represents a team that can be added to a tournament + * (in the prototype there is no functionality for the team) + */ public class Team implements Participant { private String name; private List players; private Person contactPerson; - public Team(String name){ + private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName()); + + /** + * Constructor to initiate a team, sets its name + * + * @param name the new name to be set + */ + public Team(String name) { + logger.fine("Setting the new name of the team as: " + name); setName(name); players = new ArrayList<>(); } - public void addPlayer(Player player){ + /** + * Method to add a new player to a team + * + * @param player new player to be added to a team + */ + public void addPlayer(Player player) { + logger.fine("Adding new Player named: " + player + "into the team"); players.add(player); } + /** + * Method to return the name of the team + * + * @return the name of the team + */ @Override public String getName() { + logger.fine("Returnining the name of the team:" + name); return name; } + /** + * @param name + */ @Override public void setName(String name) { this.name = name; } + /** + * Method that sets a complete List of all players as players of the team + * + * @param players List of Players to be set + */ public void setPlayers(List players) { + logger.fine("Inserts Player"); this.players = players; } + /** + * Method to get the List of all Players in a team + * + * @return List of all players in team + */ public List getPlayers() { + logger.fine("Returning List of all players in " + getName()); return players; } + /** + * Override of equals Method to compare teams with each other + * + * @param participant + * @return true if teams are the same false if not. + */ @Override public boolean equals(Participant participant) { return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase()); } + //TODO ??? @Override public void change(Participant participant) { return; } + /** + * Method to get the current contact Person of a team + * + * @return + */ public Person getContactPerson() { + logger.fine("Returning contact Person of team " + getName()); return contactPerson; } + /** + * Method to set a Person as a contact person of a team + * + * @param contactPerson + */ public void setContactPerson(Person contactPerson) { + logger.fine("Setting " + contactPerson + " as a contact Person for team " + getName()); this.contactPerson = contactPerson; } + /** + * Override of toString method, that returns the current name + * + * @return name in form of a String + */ @Override - public String toString(){ + public String toString() { return name; } } -- 2.40.1 From befa159f909d3880458df7efdc153c04bbaddb69 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 13 May 2022 01:36:54 +0200 Subject: [PATCH 2/8] Added Java Doc and Logger to Player --- .../projekt2/turnierverwaltung/Player.java | 79 +++++++++++++++++-- 1 file changed, 71 insertions(+), 8 deletions(-) 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 29bb2c6..bf1f772 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java @@ -1,54 +1,117 @@ package ch.zhaw.projekt2.turnierverwaltung; -import java.text.DateFormat; -import java.text.SimpleDateFormat; + import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.logging.Logger; -public class Player extends Person implements Participant{ +/** + * Class Representing a single Player + */ +public class Player extends Person implements Participant { private LocalDate dateOfBirth; + private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName()); + + /** + * Constructor of player initializes a new player setting sever attributes like firstname, name birthdate usw. + * and checking if the format is valid + * + * @param firstName the firstname of the player + * @param name the name of the player + * @param phoneNumber the phone number of the player + * @param dateOfBirth the birthdate of the player + * @throws InvalidNameException thrown when the name or firstname are not in a valid format + * @throws InvalidPhoneNumberException thrown when the phone number is not in a valid format + */ public Player(String firstName, String name, String phoneNumber, String dateOfBirth) throws InvalidNameException, InvalidPhoneNumberException { super(firstName, name, phoneNumber); + logger.fine("initialized super of Player with firstname, name and phone number"); + logger.finer("Setting the date of birth as:" + dateOfBirth); setDateOfBirth(dateOfBirth); + logger.finer("finished initializing the Player:" + name); } + /** + * Method to get the birthday of a player + * + * @return the birthday of a player + */ public LocalDate getDateOfBirth() { + logger.fine("returning the birthday of " + getName()); return dateOfBirth; } - public String getFormatedDateOfBirth(){ - try{ + /** + * Method that returns the date of birth formatted in eu way dd.MM.YYYY and as String + * + * @return String of formatted date + */ + public String getFormattedDateOfBirth() { + logger.finer("Trying to get the formated date"); + try { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); - return dateOfBirth.format(formatter); + logger.fine("Returning the formatted birthdate of player: " + getName()); + return dateOfBirth.format( + formatter); } catch (Exception e) { - //todo handle and logging + logger.warning("Failed to get formatted date for player " + getName() + "Error: " + e); + //TODO handle return ""; } } + /** + * Method to set the date of Birth with a String provided. + * @param dateOfBirth to be as a String + */ public void setDateOfBirth(String dateOfBirth) { - if(dateOfBirth.length() > 0) { + logger.finer("Trying to set of birth with the String " + dateOfBirth + " provided"); + if (dateOfBirth.length() > 0) { + String[] date = dateOfBirth.split("\\."); this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0])); + logger.fine(""); + logger.fine("Date of birth of" + getName() + " has been set to " + dateOfBirth); } else { + logger.warning("Date of birth of " + getName() + " could not be set, leaving at null"); dateOfBirth = null; } } + /** + * Method that sets date of Birth with a LocalDate provided + * + * @param dateOfBirth parameter given as LocalDate + */ public void setDateOfBirth(LocalDate dateOfBirth) { + logger.fine("Setting date of birth of" + getName() + "with provided LocalDate: " + dateOfBirth); this.dateOfBirth = dateOfBirth; } + /** + * Override of equals method to compare participants against each other + * + * @param participant + * @return true if equals, false if not + */ @Override public boolean equals(Participant participant) { + logger.fine("Comparing " + participant + " with " + this); return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase()); } + /** + * Override of the change method to change a Participant with a new one + * + * @param participant the new participant to be added + */ @Override public void change(Participant participant) { + logger.fine("changing the current Player " + this + "with " + participant.getName()); Player player = (Player) participant; + setDateOfBirth(player.getDateOfBirth()); setPhoneNumber(player.getPhoneNumber()); } -- 2.40.1 From 7267fe590b25a05e145f66b7e257f42d31839b3d Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 13 May 2022 01:48:26 +0200 Subject: [PATCH 3/8] Added Java Doc and Logger to Place.java --- .../projekt2/turnierverwaltung/Place.java | 48 +++++++++++++++++-- .../projekt2/turnierverwaltung/Player.java | 1 + .../turnierverwaltung/Tournament.java | 3 +- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java index f2e35bd..bfccbf1 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java @@ -1,32 +1,70 @@ package ch.zhaw.projekt2.turnierverwaltung; import java.io.Serializable; +import java.util.logging.Logger; +/** + * Class Representing a place that can be set for a game + */ public class Place implements Serializable { private final String NAME_MATCHING_REGEX = "[a-zA-Z0-9]{1,20}"; private String name; + private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName()); + + /** + * Constructor of a place initializes it and checks if name is in valid format + * + * @param name to be set + * @throws InvalidNameException If name is invalid + */ public Place(String name) throws InvalidNameException { - if(!name.matches(NAME_MATCHING_REGEX)){ - throw new InvalidNameException("The Name is Invalid."); + if (!name.matches(NAME_MATCHING_REGEX)) { + logger.warning("Name: " + name + " does not follow the valid format"); + throw new InvalidNameException("The Name: " + name + " is in an invalid Format"); } + logger.fine("Name: " + name + " is valid and will be set for the Place"); setName(name); } + /** + * Method to get the Name of the Place as String + * + * @return name of place as String + */ public String getName() { + logger.finer("returning the name: " + name); return name; } - public void setName(String name) { + /** + * Method to set the name of a place + * + * @param name the name to be set + */ + private void setName(String name) { + logger.finer("Setting " + name + " as name of place"); this.name = name; } + /** + * Ovveride of toString to return the name as String when needed + * + * @return the name of the place as String + */ @Override - public String toString(){ + public String toString() { return name; } - public boolean equals(Place place){ + /** + * Override of equals tom compare places with each other + * + * @param place to be compared with this instance + * @return true if equals and false if not equal + */ + public boolean equals(Place place) { + logger.fine("Comparing " + place + " with " + this); return name.equals(place.getName()); } } 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 bf1f772..bb1126d 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java @@ -64,6 +64,7 @@ public class Player extends Person implements Participant { /** * Method to set the date of Birth with a String provided. + * * @param dateOfBirth to be as a String */ public void setDateOfBirth(String dateOfBirth) { 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 1ff76fd..818d4f0 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -2,6 +2,7 @@ package ch.zhaw.projekt2.turnierverwaltung; import javafx.collections.FXCollections; import javafx.collections.ObservableList; + import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; @@ -228,7 +229,7 @@ public class Tournament implements Serializable { * @param type */ public void setType(Type type) { - logger.fine("Setting the type of the tournament to: " + type); + logger.fine("Setting the type of the tournament to: " + type); this.type = type; } -- 2.40.1 From 726410f6776f9b670610235bd93e42511b7396aa Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 13 May 2022 16:12:55 +0200 Subject: [PATCH 4/8] Added Java Doc and Logger to Person --- .../projekt2/turnierverwaltung/Person.java | 68 +++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) 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 73e598b..4171ae1 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Person.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Person.java @@ -1,7 +1,11 @@ package ch.zhaw.projekt2.turnierverwaltung; import java.io.Serializable; +import java.util.logging.Logger; +/** + * Class that represents a person and holds its attributes + */ public class Person implements Serializable { private final String NAME_MATCHING_REGEX = "[a-zA-Z]{1,20}"; private final String PHONE_MATCHING_REGEX = "[\\+]?[0-9]*"; @@ -10,43 +14,94 @@ public class Person implements Serializable { private String firstName; private String phoneNumber; + private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName()); + + + /** + * Constructor to initialize a person, also in charge of checking if name and phone number follow a valid format + * + * @param firstName of the new person + * @param name of the new person + * @param phoneNumber of the new person + * @throws InvalidNameException thrown when the name or firstname does not follow the valid format + * @throws InvalidPhoneNumberException thrown when the number does not follow a valid format + */ public Person(String firstName, String name, String phoneNumber) throws InvalidNameException, InvalidPhoneNumberException { - if(!firstName.matches(NAME_MATCHING_REGEX)){ + 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)){ + } 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)){ + } 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); + logger.fine("Successfully created a new Person with Name: " + name + ", Firstname: " + + firstName + ", Phone number: " + phoneNumber); } + /** + * Method to return the name of a Person + * + * @return the name as String + */ public String getName() { + logger.fine("Returning name of:" + name); return name; } + /** + * Method to set the name of a Person + * + * @param name of the person to be set + */ public void setName(String name) { + logger.fine("Setting new name of " + this + " with: " + name); this.name = name; } public String getFirstName() { + logger.fine("Returning firstname of " + this + "that is: " + firstName); return firstName; } + /** + * Method to set the first name of a Person + * + * @param firstName the person to be set + */ public void setFirstName(String firstName) { + 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() { + logger.fine("returning phone number of " + this + "that is: " + phoneNumber); return phoneNumber; } + /** + * Method used to set the Phone number of a Person + * @param phoneNumber to be set + */ public void setPhoneNumber(String phoneNumber) { + logger.fine("Setting new phone number of " + this + " with: " + phoneNumber); this.phoneNumber = phoneNumber; } + /** + * Exception, that is used when a Phone number is in an invalid format. + */ public class InvalidPhoneNumberException extends Exception { public InvalidPhoneNumberException() { super(); @@ -58,8 +113,13 @@ public class Person implements Serializable { } + /** + * Overridden toString method to be Return the name in Format "Firstname Name". + * + * @return Returning the Name in format "Firstname Name" as String + */ @Override - public String toString(){ + public String toString() { return firstName + " " + name; } -- 2.40.1 From e0a9d963f6e283b5aeed0c87a06325ba58c31d53 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 13 May 2022 16:43:33 +0200 Subject: [PATCH 5/8] CodeCleanup in Participant, Person and Team --- .../turnierverwaltung/Participant.java | 2 +- .../projekt2/turnierverwaltung/Person.java | 36 ++++++++++--------- .../zhaw/projekt2/turnierverwaltung/Team.java | 9 +++-- .../ParticipantFormularController.java | 2 +- 4 files changed, 27 insertions(+), 22 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 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 -- 2.40.1 From 67003ad772ed4fc7bf99a6c47ee460438aae9362 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 13 May 2022 17:03:23 +0200 Subject: [PATCH 6/8] CodeCleanup in Player, Tournament and Participant --- .../ch/zhaw/projekt2/turnierverwaltung/Participant.java | 2 +- .../java/ch/zhaw/projekt2/turnierverwaltung/Player.java | 8 ++++---- .../ch/zhaw/projekt2/turnierverwaltung/Tournament.java | 2 +- 3 files changed, 6 insertions(+), 6 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 844f941..cf0ccf5 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java @@ -4,7 +4,7 @@ import java.io.Serializable; public interface Participant extends Serializable { String getName(); - void setName(String name); + void setName(String name) throws InvalidNameException; boolean equals(Participant participant); void change(Participant participant) throws Person.InvalidPhoneNumberException; } 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 69da1a0..2637ee9 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java @@ -71,9 +71,9 @@ public class Player extends Person implements Participant { */ public void setDateOfBirth(String dateOfBirth) throws InvalidDateException { logger.finer("Trying to set of birth with the String " + dateOfBirth + " provided"); - if(dateOfBirth.length() > 0) { + if (dateOfBirth.length() > 0) { String[] date = dateOfBirth.split("\\."); - try{ + try { this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0])); logger.fine("Date of birth of" + getName() + " has been set to " + dateOfBirth); } catch (NumberFormatException | IndexOutOfBoundsException e) { @@ -99,7 +99,7 @@ public class Player extends Person implements Participant { /** * Override of equals method to compare participants against each other * - * @param participant + * @param participant to be compared with this instance * @return true if equals, false if not */ @Override @@ -114,7 +114,7 @@ public class Player extends Person implements Participant { * @param participant the new participant to be added */ @Override - public void change(Participant participant) { + public void change(Participant participant) throws InvalidPhoneNumberException { logger.fine("changing the current Player " + this + "with " + participant.getName()); Player player = (Player) participant; 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 276f201..9c8c47a 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -59,7 +59,7 @@ public class Tournament implements Serializable { * * @param newParticipant the Participant to be saved or edited */ - public void saveParticipant(Participant newParticipant) { + public void saveParticipant(Participant newParticipant) throws Person.InvalidPhoneNumberException { logger.fine("Trying to add " + newParticipant + " into the tournament"); for (Participant participant : participants) { if (participant.equals(newParticipant)) { -- 2.40.1 From f38b8aff16c461365ed97411a16ee99d2313d500 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 13 May 2022 17:16:33 +0200 Subject: [PATCH 7/8] CodeCleanup in Player, Tournament and Participant --- .../projekt2/turnierverwaltung/Player.java | 4 +- .../turnierverwaltung/Tournament.java | 58 +++++++++---------- 2 files changed, 28 insertions(+), 34 deletions(-) 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 2637ee9..5cd0360 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java @@ -74,7 +74,7 @@ public class Player extends Person implements Participant { if (dateOfBirth.length() > 0) { String[] date = dateOfBirth.split("\\."); try { - this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0])); + this.dateOfBirth = LocalDate.of(Integer.parseInt(date[2]), Integer.parseInt(date[1]), Integer.parseInt(date[0])); logger.fine("Date of birth of" + getName() + " has been set to " + dateOfBirth); } catch (NumberFormatException | IndexOutOfBoundsException e) { e.printStackTrace(); @@ -105,7 +105,7 @@ public class Player extends Person implements Participant { @Override public boolean equals(Participant participant) { logger.fine("Comparing " + participant + " with " + this); - return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase()); + return getClass().equals(participant.getClass()) && toString().equalsIgnoreCase(participant.toString()); } /** 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 9c8c47a..2e3cf3e 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -76,8 +76,8 @@ public class Tournament implements Serializable { /** * Method to remove an existing participant throws error if participant could not be found * - * @param participant - * @throws ParticipantNotExistsException + * @param participant to be removed + * @throws ParticipantNotExistsException thrown when the participant could not be found */ public void removeParticipant(Participant participant) throws ParticipantNotExistsException { logger.finer("Trying to remove " + participant + " from participants List"); @@ -120,8 +120,9 @@ public class Tournament implements Serializable { } /** - * @param place - * @throws PlaceNotExistsException + * Method that removes a place from the List, also checks if place is in the list + * @param place to be removed + * @throws PlaceNotExistsException thrown when the place could not be found */ public void removePlace(Place place) throws PlaceNotExistsException { if (!places.contains(place)) { @@ -159,7 +160,7 @@ public class Tournament implements Serializable { } else { - logger.warning("In the prototype the only accessible game schedule is the ko modus"); + logger.warning("In the prototype the only accessible game schedule is the ko mods"); } } @@ -209,7 +210,7 @@ public class Tournament implements Serializable { } /** - * Settermethod for the name of the tournament + * Setter method for the name of the tournament * * @param name the new name that should be set */ @@ -218,7 +219,7 @@ public class Tournament implements Serializable { } /** - * Gettermethod to get the type of the tournament + * Getter method to get the type of the tournament * * @return the type of the tournament */ @@ -230,7 +231,7 @@ public class Tournament implements Serializable { /** * Setter Method to set the type of the tournament * - * @param type + * @param type the type to be set */ public void setType(Type type) { logger.fine("Setting the type of the tournament to: " + type); @@ -238,7 +239,7 @@ public class Tournament implements Serializable { } /** - * Gettermethod to get the Complete GameList + * Getter method to get the Complete GameList * * @return the complete GameList */ @@ -254,17 +255,26 @@ public class Tournament implements Serializable { public enum Type { KO("KO-System"); //GROUPS("Gruppenspiele"); //Type GROUPS is not implemented in this prototype. - private String name; + private final String name; - private Type(String name) { + Type(String name) { this.name = name; } + /** + * Overridden toString method to return the name + * @return the name of the type + */ @Override public String toString() { return name; } + /** + * Method to return an Observable List containing all types + * + * @return the Observable list with all types + */ public static ObservableList getObservableList() { ObservableList items = FXCollections.observableArrayList(); items.addAll(values()); @@ -275,11 +285,7 @@ public class Tournament implements Serializable { /** * Custom exception thrown when an invalid file is chosen */ - public class InvalidTypeException extends Exception { - public InvalidTypeException() { - super(); - } - + public static class InvalidTypeException extends Exception { public InvalidTypeException(String errorMessage) { super(errorMessage); } @@ -287,13 +293,9 @@ public class Tournament implements Serializable { } /** - * Custom Expeption thrown when a Participant does not exist + * Custom Exception thrown when a Participant does not exist */ - public class ParticipantNotExistsException extends Exception { - public ParticipantNotExistsException() { - super(); - } - + public static class ParticipantNotExistsException extends Exception { public ParticipantNotExistsException(String errorMessage) { super(errorMessage); } @@ -303,11 +305,7 @@ public class Tournament implements Serializable { /** * Custom Exception thrown when a Place does not exist */ - public class PlaceNotExistsException extends Exception { - public PlaceNotExistsException() { - super(); - } - + public static class PlaceNotExistsException extends Exception { public PlaceNotExistsException(String errorMessage) { super(errorMessage); } @@ -317,11 +315,7 @@ public class Tournament implements Serializable { /** * Custom Exception thrown when the number of participants is not valid */ - public class NumberOfParticipantInvalidException extends Exception { - public NumberOfParticipantInvalidException() { - super(); - } - + public static class NumberOfParticipantInvalidException extends Exception { public NumberOfParticipantInvalidException(String msg) { super(msg); } -- 2.40.1 From 7fd058a528ebe8e08ee37bafbb862b339ac7daba Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 13 May 2022 17:48:42 +0200 Subject: [PATCH 8/8] CodeCleanup in Player, Tournament, Place, Person, Participant and Team --- .../turnierverwaltung/Participant.java | 29 +++++++++++++++++++ .../projekt2/turnierverwaltung/Person.java | 2 +- .../projekt2/turnierverwaltung/Place.java | 8 +++-- .../projekt2/turnierverwaltung/Player.java | 11 ++----- .../zhaw/projekt2/turnierverwaltung/Team.java | 14 +++++---- .../turnierverwaltung/Tournament.java | 4 +-- 6 files changed, 48 insertions(+), 20 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 cf0ccf5..9377e63 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java @@ -2,9 +2,38 @@ package ch.zhaw.projekt2.turnierverwaltung; import java.io.Serializable; +/** + * Interface that defines the common functionality of a Participant, used by Players and Teams + */ public interface Participant extends Serializable { + /** + * Method that will be used to get + * + * @return the name + */ String getName(); + + /** + * Method to set a participants name + * + * @param name to be set + * @throws InvalidNameException if the name does not follow the correct format + */ void setName(String name) throws InvalidNameException; + + /** + * Method to compare two participants with each other + * + * @param participant to be compared to the current instance + * @return true if equal, false if not + */ boolean equals(Participant participant); + + /** + * Method to change out participants + * + * @param participant to be exchanged + * @throws Person.InvalidPhoneNumberException if phone number does not follow the correct formatting + */ 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 4fa62b8..f7df958 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Person.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Person.java @@ -107,7 +107,7 @@ public class Person implements Serializable { /** * Exception, that is used when a Phone number is in an invalid format. */ - public class InvalidPhoneNumberException extends Exception { + public static class InvalidPhoneNumberException extends Exception { public InvalidPhoneNumberException(String errorMessage) { super(errorMessage); diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java index 3d1b2ca..a85fb5b 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java @@ -48,7 +48,7 @@ public class Place implements Serializable { } /** - * Ovveride of toString to return the name as String when needed + * Override of toString to return the name as String when needed * * @return the name of the place as String */ @@ -68,7 +68,11 @@ public class Place implements Serializable { return name.equals(place.getName()); } + /** + * Functionality to save more details than the name about a place is not implemented in this prototype, + * so no functionality is set yet to change the place. + * @param place to be changed + */ public void change(Place place) { - //TODO: If Place gets more developed in future releases } } 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 5cd0360..0ca2637 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java @@ -50,12 +50,11 @@ public class Player extends Person implements Participant { * @return String of formatted date */ public String getFormattedDateOfBirth() { - logger.finer("Trying to get the formated date"); + logger.finer("Trying to get the formatted date"); try { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); logger.fine("Returning the formatted birthdate of player: " + getName()); - return dateOfBirth.format( - formatter); + return dateOfBirth.format(formatter); } catch (Exception e) { logger.warning("Failed to get formatted date for player " + getName() + "Error: " + e); //TODO handle @@ -122,11 +121,7 @@ public class Player extends Person implements Participant { setPhoneNumber(player.getPhoneNumber()); } - public class InvalidDateException extends Exception { - public InvalidDateException() { - super(); - } - + public static class InvalidDateException extends Exception { public InvalidDateException(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 de2a18c..105562d 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java @@ -44,12 +44,14 @@ public class Team implements Participant { */ @Override public String getName() { - logger.fine("Returnining the name of the team:" + name); + logger.fine("Returning the name of the team:" + name); return name; } /** - * @param name + * Method to set the name of a team + * + * @param name of the team */ @Override public void setName(String name) { @@ -84,7 +86,7 @@ public class Team implements Participant { */ @Override public boolean equals(Participant participant) { - return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase()); + return getClass().equals(participant.getClass()) && toString().equalsIgnoreCase(participant.toString()); } /** @@ -97,9 +99,9 @@ public class Team implements Participant { } /** - * Method to get the current contact Person of a team + * Method to get the current contact person of a team * - * @return + * @return the current contact person */ public Person getContactPerson() { logger.fine("Returning contact Person of team " + getName()); @@ -109,7 +111,7 @@ public class Team implements Participant { /** * Method to set a Person as a contact person of a team * - * @param contactPerson + * @param contactPerson to be set */ public void setContactPerson(Person contactPerson) { logger.fine("Setting " + contactPerson + " as a contact Person for team " + getName()); 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 2e3cf3e..fe371e1 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -157,10 +157,8 @@ public class Tournament implements Serializable { logger.warning("Invalid number of participants only participants 2^n allowed"); throw new NumberOfParticipantInvalidException("Can not Create Game Schedule for KO Modus"); } - - } else { - logger.warning("In the prototype the only accessible game schedule is the ko mods"); + logger.warning("In the prototype the only accessible game schedule is the ko modus"); } } -- 2.40.1