From 5034203409023de06e6363d5bd2a038cf8f721be Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sun, 1 May 2022 11:10:21 +0200 Subject: [PATCH] extracted Method tournamentExists to FileIO.java --- .../java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java | 9 +++++++++ .../main/tournamentList/TournamentListController.java | 8 +++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java index 9a9aa23..2fbcf20 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java @@ -46,6 +46,15 @@ public class FileIO { return tournamentFiles; } + public boolean tournamentExists(String name){ + for(TournamentFile file : getList()) { + if(file.toString().toLowerCase().equals(name.toLowerCase())){ + return true; + } + } + return false; + } + /** * @param tournamentFile * @return diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/TournamentListController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/TournamentListController.java index 1547ab1..f06fe19 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/TournamentListController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/TournamentListController.java @@ -53,11 +53,9 @@ public class TournamentListController extends FXController { @FXML void createTournament(ActionEvent event) { - for(FileIO.TournamentFile file : getFileIO().getList()) { - if(file.toString().equals(tournamentNameField.getText())){ - return; //TODO handle and logging - // Tournament with same name exists already. - } + if(getFileIO().tournamentExists(tournamentNameField.getText())){ + System.out.println("Tournament with same name exists already."); + return; //TODO handle and logging } try { Tournament tournament = new Tournament(tournamentNameField.getText(), modusChoiceBox.getValue());