From 3ebf9c5072d243117fba73c7ba7348c041df663e Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 12 May 2022 22:41:18 +0200 Subject: [PATCH 1/3] added Exception for Invalid Date --- .../projekt2/turnierverwaltung/Player.java | 24 ++++++++++++++++--- .../TournamentDecorator.java | 3 +++ 2 files changed, 24 insertions(+), 3 deletions(-) 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 29bb2c6..20c78d0 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java @@ -9,7 +9,7 @@ public class Player extends Person implements Participant{ private LocalDate dateOfBirth; - public Player(String firstName, String name, String phoneNumber, String dateOfBirth) throws InvalidNameException, InvalidPhoneNumberException { + public Player(String firstName, String name, String phoneNumber, String dateOfBirth) throws InvalidNameException, InvalidPhoneNumberException, InvalidDateException { super(firstName, name, phoneNumber); setDateOfBirth(dateOfBirth); } @@ -28,10 +28,16 @@ public class Player extends Person implements Participant{ } } - public void setDateOfBirth(String dateOfBirth) { + public void setDateOfBirth(String dateOfBirth) throws InvalidDateException { if(dateOfBirth.length() > 0) { String[] date = dateOfBirth.split("\\."); - this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0])); + try{ + this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0])); + } catch (NumberFormatException e) { + e.printStackTrace(); + throw new InvalidDateException("Date invalid"); + } + } else { dateOfBirth = null; } @@ -52,4 +58,16 @@ public class Player extends Person implements Participant{ setDateOfBirth(player.getDateOfBirth()); setPhoneNumber(player.getPhoneNumber()); } + + public class InvalidDateException extends Exception { + public InvalidDateException() { + super(); + } + + public InvalidDateException(String errorMessage) { + super(errorMessage); + } + + } + } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java index 28d6bac..55dc2d7 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java @@ -128,6 +128,9 @@ public class TournamentDecorator implements IsObservable{ } catch (Person.InvalidPhoneNumberException e) { e.printStackTrace(); //TODO handle and logging factoryDecorator.printMessageToFooter("Invalide Telefonnummer",true); + } catch (Player.InvalidDateException e) { + e.printStackTrace(); + factoryDecorator.printMessageToFooter("Ungültiges Geburtsdatum", true); } } From ddfbb9bbd0b8917345c54566ea2e499f44f15441 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 12 May 2022 22:45:10 +0200 Subject: [PATCH 2/3] added error Message for file reading error --- .../zhaw/projekt2/turnierverwaltung/FactoryDecorator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java index e993fad..0026069 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java @@ -51,11 +51,11 @@ public class FactoryDecorator implements IsObservable{ try { factory.setTournament(fileIO.loadTournament(tournamentFile)); openScheduleView(); - } catch (IOException e) { + clearMessage(false); + } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } //TODO handle and logging + printMessageToFooter("Fehler beim lesen der Datei.", true); + } //TODO handle and logging } public void openTournamentList() { From 280d2ebda38b9f92eccbe4028ed6a3c7e7ad2230 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 12 May 2022 23:21:17 +0200 Subject: [PATCH 3/3] fixed Error when IndexOutOfBoundsException in setDateofBirtch in Player.java --- .../main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 20c78d0..648776f 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java @@ -33,7 +33,7 @@ public class Player extends Person implements Participant{ String[] date = dateOfBirth.split("\\."); try{ this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0])); - } catch (NumberFormatException e) { + } catch (NumberFormatException | IndexOutOfBoundsException e) { e.printStackTrace(); throw new InvalidDateException("Date invalid"); }