From c0dbbdc990a68a99b2d913bba9698d7e0894e924 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 14 Jan 2018 22:48:02 +0100 Subject: Modifying the implementation of the Main, with Validation feature and exception handling --- src/main/java/fr/umlv/java/wallj/Main.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/umlv/java/wallj/Main.java b/src/main/java/fr/umlv/java/wallj/Main.java index 3b3ad54..0ac4136 100644 --- a/src/main/java/fr/umlv/java/wallj/Main.java +++ b/src/main/java/fr/umlv/java/wallj/Main.java @@ -2,6 +2,7 @@ package fr.umlv.java.wallj; import fr.umlv.java.wallj.board.Board; import fr.umlv.java.wallj.board.BoardParser; +import fr.umlv.java.wallj.board.BoardValidator; import fr.umlv.java.wallj.viewer.Viewer; import fr.umlv.zen5.Application; @@ -32,20 +33,31 @@ public class Main { } public static void main(String[] args) { - java.util.List boards = new LinkedList<>(); + List boards = new LinkedList<>(); try { List boardPaths = Main.getResourcePaths(args); for (Path path : boardPaths) { - boards.add(BoardParser.parse(path)); + BoardValidator boardValidator = new BoardValidator(BoardParser.parse(path)); + boards.add( + boardValidator.validate(BoardValidator.Constraint::hasActualReachableBlocks, "Some supposed reachable blocks are not reachable.") + .validate(BoardValidator.Constraint::hasMandatoryBlocks, "Some mandatory blocks are missing.") + .validate(BoardValidator.Constraint::isBounded, "The board is not correctly bounded.") + .validate(BoardValidator.Constraint::isHollow, "The board must have a unique and simple interior.") + .get()); } Viewer viewer = new Viewer(boards); - Application.run(Color.BLACK, viewer::eventLoop); + Application.run(Color.WHITE, viewer::eventLoop); } catch (URISyntaxException e) { System.err.println(e.getMessage()); System.exit(1); } catch (IOException e) { System.err.println(e.getMessage()); System.exit(2); + } catch (BoardValidator.ValidationException e) { + for (Throwable throwable : e.getSuppressed()) { + System.err.println(throwable.getMessage()); + } + System.exit(3); } } } -- cgit v1.2.3