Language dev #52
|
@ -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();
|
||||
void setName(String name);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
void change(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;
|
||||
}
|
||||
|
|
|
@ -1,56 +1,113 @@
|
|||
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]*";
|
||||
private final String PHONE_MATCHING_REGEX = "[+]?[0-9]*";
|
||||
|
||||
private String name;
|
||||
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)){
|
||||
throw new InvalidNameException("The First name is Invalid.");
|
||||
} else if(!name.matches(NAME_MATCHING_REGEX)){
|
||||
throw new InvalidNameException("The Last name is Invalid");
|
||||
} else if(!phoneNumber.matches(PHONE_MATCHING_REGEX)){
|
||||
throw new InvalidPhoneNumberException("The entered Phone Number is invalid.");
|
||||
}
|
||||
logger.finer("Trying to initialize a new person with name: " + name + ", first name: "
|
||||
+ firstName + ", Phone number: " + phoneNumber);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
/**
|
||||
* Method to set the name of a Person
|
||||
*
|
||||
* @param name of the person to be set
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
logger.fine("Returning firstname of " + this + "that is: " + firstName);
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
/**
|
||||
* Method to set the first name of a Person
|
||||
*
|
||||
* @param firstName the person to be set
|
||||
*/
|
||||
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() {
|
||||
logger.fine("returning phone number of " + this + "that is: " + phoneNumber);
|
||||
return phoneNumber;
|
||||
}
|
||||
|
||||
public void setPhoneNumber(String phoneNumber) {
|
||||
/**
|
||||
* Method used to set the Phone number of a Person
|
||||
*
|
||||
* @param phoneNumber to be set
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
public class InvalidPhoneNumberException extends Exception {
|
||||
public InvalidPhoneNumberException() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Exception, that is used when a Phone number is in an invalid format.
|
||||
*/
|
||||
public static class InvalidPhoneNumberException extends Exception {
|
||||
|
||||
public InvalidPhoneNumberException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
|
@ -58,8 +115,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,36 +1,78 @@
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,69 +1,127 @@
|
|||
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, InvalidDateException {
|
||||
|
||||
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 formatted date");
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
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) throws InvalidDateException {
|
||||
if(dateOfBirth.length() > 0) {
|
||||
logger.finer("Trying to set of birth with the String " + dateOfBirth + " provided");
|
||||
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]));
|
||||
try {
|
||||
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();
|
||||
logger.warning("Date of birth of " + getName() + " could not be set, leaving at null");
|
||||
throw new InvalidDateException("Date invalid");
|
||||
}
|
||||
|
||||
} else {
|
||||
dateOfBirth = null;
|
||||
logger.warning("Date of birth of " + getName() + " could not be set, leaving at 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 to be compared with this instance
|
||||
* @return true if equals, false if not
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Participant participant) {
|
||||
return getClass().equals(participant.getClass()) && toString().toLowerCase().equals(participant.toString().toLowerCase());
|
||||
logger.fine("Comparing " + participant + " with " + this);
|
||||
return getClass().equals(participant.getClass()) && toString().equalsIgnoreCase(participant.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
public void change(Participant participant) throws InvalidPhoneNumberException {
|
||||
logger.fine("changing the current Player " + this + "with " + participant.getName());
|
||||
Player player = (Player) participant;
|
||||
|
||||
setDateOfBirth(player.getDateOfBirth());
|
||||
setPhoneNumber(player.getPhoneNumber());
|
||||
}
|
||||
|
||||
public class InvalidDateException extends Exception {
|
||||
public InvalidDateException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static class InvalidDateException extends Exception {
|
||||
public InvalidDateException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
|
|
@ -2,59 +2,129 @@ 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<Player> 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("Returning the name of the team:" + name);
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the name of a team
|
||||
*
|
||||
* @param name of the team
|
||||
*/
|
||||
@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<Player> 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<Player> getPlayers() {
|
||||
logger.fine("Returning List of all players in " + getName());
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override of equals Method to compare teams with each other
|
||||
*
|
||||
* @param participant to be compared with this instance
|
||||
* @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());
|
||||
return getClass().equals(participant.getClass()) && toString().equalsIgnoreCase(participant.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the current contact person of a team
|
||||
*
|
||||
* @return the current contact person
|
||||
*/
|
||||
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 to be set
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
@ -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)) {
|
||||
|
@ -156,8 +157,6 @@ 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 modus");
|
||||
}
|
||||
|
@ -209,7 +208,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 +217,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 +229,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 +237,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 +253,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 +283,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 +291,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 +303,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 +313,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);
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public class TournamentDecorator implements IsObservable{
|
|||
} catch (Tournament.InvalidTypeException e) {
|
||||
e.printStackTrace();
|
||||
//TODO: Logger
|
||||
factoryDecorator.printMessageToFooter("Turniermodus nicht möglich",true);
|
||||
factoryDecorator.printMessageToFooter("Turniermodus nicht moeglich",true);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -113,7 +113,7 @@ public class TournamentDecorator implements IsObservable{
|
|||
factoryDecorator.clearMessage(true);
|
||||
} catch (Tournament.NumberOfParticipantInvalidException e) {
|
||||
e.printStackTrace();
|
||||
factoryDecorator.printMessageToFooter("Anzahl Teilnehmer nicht vielfaches von 2",true);
|
||||
factoryDecorator.printMessageToFooter("Anzahl Teilnehmer muss mindestens 4 betragen und eine Potenz von 2 sein.",true);
|
||||
}
|
||||
informListener();
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ public class TournamentDecorator implements IsObservable{
|
|||
factoryDecorator.printMessageToFooter("Invalide Telefonnummer",true);
|
||||
} catch (Player.InvalidDateException e) {
|
||||
e.printStackTrace();
|
||||
factoryDecorator.printMessageToFooter("Ungültiges Geburtsdatum", true);
|
||||
factoryDecorator.printMessageToFooter("Ungueltiges Geburtsdatum", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
|
||||
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ButtonBar;
|
||||
import javafx.scene.control.ButtonType;
|
||||
|
||||
public class AlertNewSchedule extends Alert {
|
||||
private ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES);
|
||||
private ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO);
|
||||
private boolean result;
|
||||
|
||||
public AlertNewSchedule() {
|
||||
super(AlertType.WARNING);
|
||||
setTitle("Neu erstellen");
|
||||
setHeaderText("Spielplan neu erstellen?");
|
||||
setContentText("Sind Sie sicher, dass Sie den Spielplan neu erstellen moechten?\nAlle Spielfortschritte gehen daraufhin verloren!");
|
||||
getButtonTypes().setAll(yesButton,noButton);
|
||||
}
|
||||
|
||||
public boolean showAndGetResult() {
|
||||
showAndWait().ifPresent(input -> {
|
||||
result = input == yesButton;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -39,8 +39,15 @@ public class GameScheduleController extends FXController {
|
|||
|
||||
@FXML
|
||||
void createNewSchedule(ActionEvent event) {
|
||||
if (getTournamentDecorator().getTournament().getGameList().size() > 0) {
|
||||
AlertNewSchedule alert = new AlertNewSchedule();
|
||||
if (alert.showAndGetResult()) {
|
||||
getTournamentDecorator().createNewGameSchedule();
|
||||
}
|
||||
} else {
|
||||
getTournamentDecorator().createNewGameSchedule();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
void openPlacesFormular(ActionEvent event) {
|
||||
|
|
|
@ -87,7 +87,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
|
||||
|
|
|
@ -21,9 +21,7 @@ public class AlertDelete extends Alert {
|
|||
public boolean showAndGetResult() {
|
||||
result = false;
|
||||
showAndWait().ifPresent(type -> {
|
||||
if (type == yesButton) {
|
||||
result = true;
|
||||
}
|
||||
result = type == yesButton;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue