|
|
|
@@ -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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|