added Participant List to Tournament.java
This commit is contained in:
parent
678060ecc0
commit
b09929da19
|
@ -3,4 +3,5 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
|||
public interface Participant {
|
||||
String getName();
|
||||
void setName(String name);
|
||||
boolean equals(Participant participant);
|
||||
}
|
||||
|
|
|
@ -18,4 +18,10 @@ public class Player extends Person implements Participant{
|
|||
public void setDateOfBirth(Date dateOfBirth) {
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Participant participant) {
|
||||
return getClass().equals(participant.getClass()) && getName().equals(participant.getName()) &&
|
||||
getFirstName().equals(((Player) participant).getFirstName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,11 @@ public class Team implements Participant {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Participant participant) {
|
||||
return getClass().equals(participant.getClass()) && name.equals(participant.getName());
|
||||
}
|
||||
|
||||
public Person getContactPerson() {
|
||||
return contactPerson;
|
||||
}
|
||||
|
|
|
@ -4,11 +4,14 @@ import javafx.collections.FXCollections;
|
|||
import javafx.collections.ObservableList;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Tournament implements Serializable {
|
||||
private String name;
|
||||
private Type type;
|
||||
private List<Participant> participants;
|
||||
|
||||
|
||||
|
||||
|
@ -21,6 +24,22 @@ public class Tournament implements Serializable {
|
|||
|
||||
setName(name);
|
||||
setType(type);
|
||||
participants = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addParticipant(Participant newParticipant) throws ParticipantExistsException {
|
||||
for(Participant participant : participants){
|
||||
if(participant.equals(newParticipant)){
|
||||
throw new ParticipantExistsException("A Participant with the same Name exists already.");
|
||||
}
|
||||
}
|
||||
participants.add(newParticipant);
|
||||
}
|
||||
|
||||
public void removeParticipant(Participant participant) throws ParticipantNotExistsException {
|
||||
if(!participants.contains(participant)){
|
||||
throw new ParticipantNotExistsException("The given Participant is not part of this Tournament");
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -82,5 +101,27 @@ public class Tournament implements Serializable {
|
|||
|
||||
}
|
||||
|
||||
public class ParticipantExistsException extends Exception {
|
||||
public ParticipantExistsException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ParticipantExistsException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ParticipantNotExistsException extends Exception {
|
||||
public ParticipantNotExistsException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ParticipantNotExistsException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue