From 54a428cde27c39ae2a19290b65a54a09b99c7efa Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 13 May 2022 13:48:38 +0200 Subject: [PATCH] throw PlaceExistsExceptoin if place exists already. --- .../java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 1ff76fd..e267156 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -110,7 +110,11 @@ public class Tournament implements Serializable { * @throws PlaceExistsException if the place already exists */ public void addPlace(Place newPlace) throws PlaceExistsException { - places.removeIf(place -> place.equals(newPlace)); + for(Place place : places){ + if(place.getName().equals(newPlace.getName())){ + throw new PlaceExistsException("Place with same name exists already."); + } + } places.add(newPlace); }