diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java index e48f3a1..31c2a39 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Participant.java @@ -3,4 +3,5 @@ package ch.zhaw.projekt2.turnierverwaltung; public interface Participant { String getName(); void setName(String name); + boolean equals(Participant participant); } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java index 4273fd1..f922512 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java @@ -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()); + } } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java index 880cc13..23ca660 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java @@ -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; } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java index e46f505..878985f 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -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 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); + } + + } + }