diff options
author | Adam NAILI | 2018-02-04 02:10:58 +0100 |
---|---|---|
committer | Adam NAILI | 2018-02-04 02:10:58 +0100 |
commit | b73f194a59936d0a76374879f781e19bc2433137 (patch) | |
tree | 94dde452e9b5191bdaad53b6ca4ad7cf5653951c | |
parent | f923d5c92b40cc1fad21d931ce922e31758cce18 (diff) | |
download | wallj-b73f194a59936d0a76374879f781e19bc2433137.tar.gz |
Refactoring Main (not totally working yet, missing return statement in catches)
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/viewer/Main.java | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/viewer/Main.java b/src/main/java/fr/umlv/java/wallj/viewer/Main.java index 3055da8..d133f78 100644 --- a/src/main/java/fr/umlv/java/wallj/viewer/Main.java +++ b/src/main/java/fr/umlv/java/wallj/viewer/Main.java | |||
@@ -18,7 +18,6 @@ public class Main { | |||
18 | 18 | ||
19 | private static final String DEFAULT_MAP_NAME = "/maps/level0.txt"; | 19 | private static final String DEFAULT_MAP_NAME = "/maps/level0.txt"; |
20 | 20 | ||
21 | |||
22 | private static FileSystem fileSystemForContext(URI uri) throws URISyntaxException, IOException { | 21 | private static FileSystem fileSystemForContext(URI uri) throws URISyntaxException, IOException { |
23 | boolean isInJar = Objects.equals(Main.class.getProtectionDomain().getCodeSource().getLocation().getProtocol(), "jar"); | 22 | boolean isInJar = Objects.equals(Main.class.getProtectionDomain().getCodeSource().getLocation().getProtocol(), "jar"); |
24 | if (isInJar) {//JAR from command line handling | 23 | if (isInJar) {//JAR from command line handling |
@@ -43,32 +42,45 @@ public class Main { | |||
43 | return paths; | 42 | return paths; |
44 | } | 43 | } |
45 | 44 | ||
46 | public static void main(String[] args) { | 45 | //TODO Split Parse and validation + add useless return to satisfy this crazy compiler |
47 | List<Board> boards = new LinkedList<>(); | 46 | private static Board validateBoardFromPath(Path path) { |
48 | try { | 47 | try { |
49 | List<Path> boardPaths = Main.getResourcePaths(); | 48 | BoardValidator boardValidator = new BoardValidator(BoardParser.parse(path)); |
50 | for (Path path : boardPaths) { | 49 | return boardValidator.validate(BoardValidator.Constraint::hasActualReachableBlocks, "Some supposed reachable blocks are not reachable.") |
51 | BoardValidator boardValidator = new BoardValidator(BoardParser.parse(path)); | 50 | .validate(BoardValidator.Constraint::hasMandatoryBlocks, "Some mandatory blocks are missing.") |
52 | boards.add( | 51 | .validate(BoardValidator.Constraint::isBounded, "The board is not correctly bounded.") |
53 | boardValidator.validate(BoardValidator.Constraint::hasActualReachableBlocks, "Some supposed reachable blocks are not reachable.") | 52 | .validate(BoardValidator.Constraint::isHollow, "The board must have a unique and simple interior.") |
54 | .validate(BoardValidator.Constraint::hasMandatoryBlocks, "Some mandatory blocks are missing.") | 53 | .get(); |
55 | .validate(BoardValidator.Constraint::isBounded, "The board is not correctly bounded.") | ||
56 | .validate(BoardValidator.Constraint::isHollow, "The board must have a unique and simple interior.") | ||
57 | .get()); | ||
58 | } | ||
59 | Viewer viewer = new Viewer(boards); | ||
60 | Application.run(Color.WHITE, viewer::eventLoop); | ||
61 | } catch (URISyntaxException e) { | ||
62 | System.err.println(e.getMessage()); | ||
63 | System.exit(1); | ||
64 | } catch (IOException e) { | 54 | } catch (IOException e) { |
65 | System.err.println(e.getMessage()); | 55 | System.err.println(e.getMessage()); |
66 | System.exit(2); | 56 | System.exit(2); |
67 | } catch (BoardValidator.ValidationException e) { | 57 | } catch (BoardValidator.ValidationException e) { |
58 | System.err.println(path.toString() + ':'); | ||
68 | for (Throwable throwable : e.getSuppressed()) { | 59 | for (Throwable throwable : e.getSuppressed()) { |
69 | System.err.println(throwable.getMessage()); | 60 | System.err.println(throwable.getMessage()); |
70 | } | 61 | } |
71 | System.exit(3); | 62 | System.exit(3); |
72 | } | 63 | } |
73 | } | 64 | } |
65 | |||
66 | private static List<Board> validateBoardsFromPaths(List<Path> boardPaths) { | ||
67 | List<Board> boards = new LinkedList<>(); | ||
68 | for (Path path : boardPaths) { | ||
69 | boards.add(validateBoardFromPath(path)); | ||
70 | } | ||
71 | return boards; | ||
72 | } | ||
73 | |||
74 | public static void main(String[] args) { | ||
75 | try { | ||
76 | Viewer viewer = new Viewer(validateBoardsFromPaths(Main.getResourcePaths())); | ||
77 | Application.run(Color.WHITE, viewer::eventLoop); | ||
78 | } catch (URISyntaxException e) { | ||
79 | System.err.println(e.getMessage()); | ||
80 | System.exit(1); | ||
81 | } catch (IOException e) { | ||
82 | System.err.println(e.getMessage()); | ||
83 | System.exit(2); | ||
84 | } | ||
85 | } | ||
74 | } | 86 | } |