Added Java Doc and Logger to Player
This commit is contained in:
parent
06003d5b54
commit
befa159f90
|
@ -1,54 +1,117 @@
|
||||||
package ch.zhaw.projekt2.turnierverwaltung;
|
package ch.zhaw.projekt2.turnierverwaltung;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
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 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 {
|
public Player(String firstName, String name, String phoneNumber, String dateOfBirth) throws InvalidNameException, InvalidPhoneNumberException {
|
||||||
super(firstName, name, phoneNumber);
|
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);
|
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() {
|
public LocalDate getDateOfBirth() {
|
||||||
|
logger.fine("returning the birthday of " + getName());
|
||||||
return dateOfBirth;
|
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");
|
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) {
|
} catch (Exception e) {
|
||||||
//todo handle and logging
|
logger.warning("Failed to get formatted date for player " + getName() + "Error: " + e);
|
||||||
|
//TODO handle
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to set the date of Birth with a String provided.
|
||||||
|
* @param dateOfBirth to be as a String
|
||||||
|
*/
|
||||||
public void setDateOfBirth(String dateOfBirth) {
|
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("\\.");
|
String[] date = dateOfBirth.split("\\.");
|
||||||
this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0]));
|
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 {
|
} else {
|
||||||
|
logger.warning("Date of birth of " + getName() + " could not be set, leaving at null");
|
||||||
dateOfBirth = null;
|
dateOfBirth = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that sets date of Birth with a LocalDate provided
|
||||||
|
*
|
||||||
|
* @param dateOfBirth parameter given as LocalDate
|
||||||
|
*/
|
||||||
public void setDateOfBirth(LocalDate dateOfBirth) {
|
public void setDateOfBirth(LocalDate dateOfBirth) {
|
||||||
|
logger.fine("Setting date of birth of" + getName() + "with provided LocalDate: " + dateOfBirth);
|
||||||
this.dateOfBirth = dateOfBirth;
|
this.dateOfBirth = dateOfBirth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override of equals method to compare participants against each other
|
||||||
|
*
|
||||||
|
* @param participant
|
||||||
|
* @return true if equals, false if not
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Participant participant) {
|
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().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
|
@Override
|
||||||
public void change(Participant participant) {
|
public void change(Participant participant) {
|
||||||
|
logger.fine("changing the current Player " + this + "with " + participant.getName());
|
||||||
Player player = (Player) participant;
|
Player player = (Player) participant;
|
||||||
|
|
||||||
setDateOfBirth(player.getDateOfBirth());
|
setDateOfBirth(player.getDateOfBirth());
|
||||||
setPhoneNumber(player.getPhoneNumber());
|
setPhoneNumber(player.getPhoneNumber());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue