Logging and docs added to classes Person, Place and Player #27 #28 #50

Merged
brandleo merged 10 commits from logging_and_docs into main 2022-05-13 17:49:39 +02:00
6 changed files with 48 additions and 20 deletions
Showing only changes of commit 7fd058a528 - Show all commits

View File

@ -2,9 +2,38 @@ package ch.zhaw.projekt2.turnierverwaltung;
import java.io.Serializable; import java.io.Serializable;
/**
* Interface that defines the common functionality of a Participant, used by Players and Teams
*/
public interface Participant extends Serializable { public interface Participant extends Serializable {
/**
* Method that will be used to get
*
* @return the name
*/
String getName(); 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; 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); 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; void change(Participant participant) throws Person.InvalidPhoneNumberException;
} }

View File

@ -107,7 +107,7 @@ public class Person implements Serializable {
/** /**
* Exception, that is used when a Phone number is in an invalid format. * 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) { public InvalidPhoneNumberException(String errorMessage) {
super(errorMessage); super(errorMessage);

View File

@ -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 * @return the name of the place as String
*/ */
@ -68,7 +68,11 @@ public class Place implements Serializable {
return name.equals(place.getName()); 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) { public void change(Place place) {
//TODO: If Place gets more developed in future releases
} }
} }

View File

@ -50,12 +50,11 @@ public class Player extends Person implements Participant {
* @return String of formatted date * @return String of formatted date
*/ */
public String getFormattedDateOfBirth() { public String getFormattedDateOfBirth() {
logger.finer("Trying to get the formated date"); logger.finer("Trying to get the formatted date");
try { try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
logger.fine("Returning the formatted birthdate of player: " + getName()); logger.fine("Returning the formatted birthdate of player: " + getName());
return dateOfBirth.format( return dateOfBirth.format(formatter);
formatter);
} catch (Exception e) { } catch (Exception e) {
logger.warning("Failed to get formatted date for player " + getName() + "Error: " + e); logger.warning("Failed to get formatted date for player " + getName() + "Error: " + e);
//TODO handle //TODO handle
@ -122,11 +121,7 @@ public class Player extends Person implements Participant {
setPhoneNumber(player.getPhoneNumber()); setPhoneNumber(player.getPhoneNumber());
} }
public class InvalidDateException extends Exception { public static class InvalidDateException extends Exception {
public InvalidDateException() {
super();
}
public InvalidDateException(String errorMessage) { public InvalidDateException(String errorMessage) {
super(errorMessage); super(errorMessage);
} }

View File

@ -44,12 +44,14 @@ public class Team implements Participant {
*/ */
@Override @Override
public String getName() { public String getName() {
logger.fine("Returnining the name of the team:" + name); logger.fine("Returning the name of the team:" + name);
return name; return name;
} }
/** /**
* @param name * Method to set the name of a team
*
* @param name of the team
*/ */
@Override @Override
public void setName(String name) { public void setName(String name) {
@ -84,7 +86,7 @@ public class Team implements Participant {
*/ */
@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().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() { public Person getContactPerson() {
logger.fine("Returning contact Person of team " + getName()); 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 * Method to set a Person as a contact person of a team
* *
* @param contactPerson * @param contactPerson to be set
*/ */
public void setContactPerson(Person contactPerson) { public void setContactPerson(Person contactPerson) {
logger.fine("Setting " + contactPerson + " as a contact Person for team " + getName()); logger.fine("Setting " + contactPerson + " as a contact Person for team " + getName());

View File

@ -157,10 +157,8 @@ public class Tournament implements Serializable {
logger.warning("Invalid number of participants only participants 2^n allowed"); logger.warning("Invalid number of participants only participants 2^n allowed");
throw new NumberOfParticipantInvalidException("Can not Create Game Schedule for KO Modus"); throw new NumberOfParticipantInvalidException("Can not Create Game Schedule for KO Modus");
} }
} else { } 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");
} }
} }