diff options
author | Adam NAILI | 2018-01-14 22:48:02 +0100 |
---|---|---|
committer | Adam NAILI | 2018-01-14 22:48:02 +0100 |
commit | c0dbbdc990a68a99b2d913bba9698d7e0894e924 (patch) | |
tree | c002b997e0a0508389ce4b6061bc4577319f923f | |
parent | 36d9bdb9ea9ae1447fd836735be93b4f96b28b0f (diff) | |
download | wallj-c0dbbdc990a68a99b2d913bba9698d7e0894e924.tar.gz |
Modifying the implementation of the Main, with Validation feature and exception handling
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/Main.java | 18 |
1 files 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; | |||
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.Board; | 3 | import fr.umlv.java.wallj.board.Board; |
4 | import fr.umlv.java.wallj.board.BoardParser; | 4 | import fr.umlv.java.wallj.board.BoardParser; |
5 | import fr.umlv.java.wallj.board.BoardValidator; | ||
5 | import fr.umlv.java.wallj.viewer.Viewer; | 6 | import fr.umlv.java.wallj.viewer.Viewer; |
6 | import fr.umlv.zen5.Application; | 7 | import fr.umlv.zen5.Application; |
7 | 8 | ||
@@ -32,20 +33,31 @@ public class Main { | |||
32 | } | 33 | } |
33 | 34 | ||
34 | public static void main(String[] args) { | 35 | public static void main(String[] args) { |
35 | java.util.List<Board> boards = new LinkedList<>(); | 36 | List<Board> boards = new LinkedList<>(); |
36 | try { | 37 | try { |
37 | List<Path> boardPaths = Main.getResourcePaths(args); | 38 | List<Path> boardPaths = Main.getResourcePaths(args); |
38 | for (Path path : boardPaths) { | 39 | for (Path path : boardPaths) { |
39 | boards.add(BoardParser.parse(path)); | 40 | BoardValidator boardValidator = new BoardValidator(BoardParser.parse(path)); |
41 | boards.add( | ||
42 | boardValidator.validate(BoardValidator.Constraint::hasActualReachableBlocks, "Some supposed reachable blocks are not reachable.") | ||
43 | .validate(BoardValidator.Constraint::hasMandatoryBlocks, "Some mandatory blocks are missing.") | ||
44 | .validate(BoardValidator.Constraint::isBounded, "The board is not correctly bounded.") | ||
45 | .validate(BoardValidator.Constraint::isHollow, "The board must have a unique and simple interior.") | ||
46 | .get()); | ||
40 | } | 47 | } |
41 | Viewer viewer = new Viewer(boards); | 48 | Viewer viewer = new Viewer(boards); |
42 | Application.run(Color.BLACK, viewer::eventLoop); | 49 | Application.run(Color.WHITE, viewer::eventLoop); |
43 | } catch (URISyntaxException e) { | 50 | } catch (URISyntaxException e) { |
44 | System.err.println(e.getMessage()); | 51 | System.err.println(e.getMessage()); |
45 | System.exit(1); | 52 | System.exit(1); |
46 | } catch (IOException e) { | 53 | } catch (IOException e) { |
47 | System.err.println(e.getMessage()); | 54 | System.err.println(e.getMessage()); |
48 | System.exit(2); | 55 | System.exit(2); |
56 | } catch (BoardValidator.ValidationException e) { | ||
57 | for (Throwable throwable : e.getSuppressed()) { | ||
58 | System.err.println(throwable.getMessage()); | ||
59 | } | ||
60 | System.exit(3); | ||
49 | } | 61 | } |
50 | } | 62 | } |
51 | } | 63 | } |