added Type checking in Tournament.java
This commit is contained in:
@@ -4,6 +4,7 @@ import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Tournament implements Serializable {
|
||||
private String name;
|
||||
@@ -11,10 +12,13 @@ public class Tournament implements Serializable {
|
||||
|
||||
|
||||
|
||||
public Tournament(String name, Type type) throws InvalidNameException {
|
||||
public Tournament(String name, Type type) throws InvalidNameException, InvalidTypeException {
|
||||
if(!name.matches("[\\w]{1,20}")){
|
||||
throw new Tournament.InvalidNameException("Invalid Name entered"); //TODO handle en logging.
|
||||
} else if(!Arrays.asList(Type.values()).contains(type)){
|
||||
throw new InvalidTypeException("Invalid Type selected"); //TODO handle en logging.
|
||||
}
|
||||
|
||||
setName(name);
|
||||
setType(type);
|
||||
}
|
||||
@@ -67,5 +71,16 @@ public class Tournament implements Serializable {
|
||||
|
||||
}
|
||||
|
||||
public class InvalidTypeException extends Exception {
|
||||
public InvalidTypeException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidTypeException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -64,8 +64,11 @@ public class TournamentListController extends FXController {
|
||||
Tournament tournament = new Tournament(tournamentNameField.getText(), modusChoiceBox.getValue());
|
||||
getFileIO().saveTournament(tournament);
|
||||
loadContent();
|
||||
tournamentNameField.clear();
|
||||
} catch (Tournament.InvalidNameException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
} catch (Tournament.InvalidTypeException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
}
|
||||
@@ -92,6 +95,7 @@ public class TournamentListController extends FXController {
|
||||
if(alert.showAndGetResult()){
|
||||
try {
|
||||
getFileIO().deleteTournament(tournamentFile);
|
||||
loadContent();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user