throw PlaceExistsExceptoin if place exists already.

This commit is contained in:
schrom01 2022-05-13 13:48:38 +02:00
parent 92d121890c
commit 54a428cde2
1 changed files with 5 additions and 1 deletions

View File

@ -110,7 +110,11 @@ public class Tournament implements Serializable {
* @throws PlaceExistsException if the place already exists * @throws PlaceExistsException if the place already exists
*/ */
public void addPlace(Place newPlace) throws PlaceExistsException { 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); places.add(newPlace);
} }