From 7fd058a528ebe8e08ee37bafbb862b339ac7daba Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 13 May 2022 17:48:42 +0200 Subject: [PATCH] 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"); } }