CodeCleanup in Player, Tournament and Participant

This commit is contained in:
Leonardo Brandenberger 2022-05-13 17:16:33 +02:00
parent 67003ad772
commit f38b8aff16
2 changed files with 28 additions and 34 deletions

View File

@ -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());
}
/**

View File

@ -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");
}
}
@ -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);
@ -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<Type> getObservableList() {
ObservableList<Type> 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);
}