From 7267fe590b25a05e145f66b7e257f42d31839b3d Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 13 May 2022 01:48:26 +0200 Subject: [PATCH] Added Java Doc and Logger to Place.java --- .../projekt2/turnierverwaltung/Place.java | 48 +++++++++++++++++-- .../projekt2/turnierverwaltung/Player.java | 1 + .../turnierverwaltung/Tournament.java | 3 +- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java index f2e35bd..bfccbf1 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Place.java @@ -1,32 +1,70 @@ package ch.zhaw.projekt2.turnierverwaltung; import java.io.Serializable; +import java.util.logging.Logger; +/** + * Class Representing a place that can be set for a game + */ public class Place implements Serializable { private final String NAME_MATCHING_REGEX = "[a-zA-Z0-9]{1,20}"; private String name; + private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName()); + + /** + * Constructor of a place initializes it and checks if name is in valid format + * + * @param name to be set + * @throws InvalidNameException If name is invalid + */ public Place(String name) throws InvalidNameException { - if(!name.matches(NAME_MATCHING_REGEX)){ - throw new InvalidNameException("The Name is Invalid."); + if (!name.matches(NAME_MATCHING_REGEX)) { + logger.warning("Name: " + name + " does not follow the valid format"); + throw new InvalidNameException("The Name: " + name + " is in an invalid Format"); } + logger.fine("Name: " + name + " is valid and will be set for the Place"); setName(name); } + /** + * Method to get the Name of the Place as String + * + * @return name of place as String + */ public String getName() { + logger.finer("returning the name: " + name); return name; } - public void setName(String name) { + /** + * Method to set the name of a place + * + * @param name the name to be set + */ + private void setName(String name) { + logger.finer("Setting " + name + " as name of place"); this.name = name; } + /** + * Ovveride of toString to return the name as String when needed + * + * @return the name of the place as String + */ @Override - public String toString(){ + public String toString() { return name; } - public boolean equals(Place place){ + /** + * Override of equals tom compare places with each other + * + * @param place to be compared with this instance + * @return true if equals and false if not equal + */ + public boolean equals(Place place) { + logger.fine("Comparing " + place + " with " + this); return name.equals(place.getName()); } } 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 bf1f772..bb1126d 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Player.java @@ -64,6 +64,7 @@ public class Player extends Person implements Participant { /** * Method to set the date of Birth with a String provided. + * * @param dateOfBirth to be as a String */ public void setDateOfBirth(String dateOfBirth) { 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..818d4f0 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -2,6 +2,7 @@ package ch.zhaw.projekt2.turnierverwaltung; import javafx.collections.FXCollections; import javafx.collections.ObservableList; + import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; @@ -228,7 +229,7 @@ public class Tournament implements Serializable { * @param type */ public void setType(Type type) { - logger.fine("Setting the type of the tournament to: " + type); + logger.fine("Setting the type of the tournament to: " + type); this.type = type; }