From b73f194a59936d0a76374879f781e19bc2433137 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Sun, 4 Feb 2018 02:10:58 +0100 Subject: Refactoring Main (not totally working yet, missing return statement in catches) --- src/main/java/fr/umlv/java/wallj/viewer/Main.java | 48 ++++++++++++++--------- 1 file 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 { private static final String DEFAULT_MAP_NAME = "/maps/level0.txt"; - private static FileSystem fileSystemForContext(URI uri) throws URISyntaxException, IOException { boolean isInJar = Objects.equals(Main.class.getProtectionDomain().getCodeSource().getLocation().getProtocol(), "jar"); if (isInJar) {//JAR from command line handling @@ -43,32 +42,45 @@ public class Main { return paths; } - public static void main(String[] args) { - List boards = new LinkedList<>(); + //TODO Split Parse and validation + add useless return to satisfy this crazy compiler + private static Board validateBoardFromPath(Path path) { try { - List boardPaths = Main.getResourcePaths(); - for (Path path : boardPaths) { - 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.WHITE, viewer::eventLoop); - } catch (URISyntaxException e) { - System.err.println(e.getMessage()); - System.exit(1); + BoardValidator boardValidator = new BoardValidator(BoardParser.parse(path)); + return 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(); } catch (IOException e) { System.err.println(e.getMessage()); System.exit(2); } catch (BoardValidator.ValidationException e) { + System.err.println(path.toString() + ':'); for (Throwable throwable : e.getSuppressed()) { System.err.println(throwable.getMessage()); } System.exit(3); } } + + private static List validateBoardsFromPaths(List boardPaths) { + List boards = new LinkedList<>(); + for (Path path : boardPaths) { + boards.add(validateBoardFromPath(path)); + } + return boards; + } + + public static void main(String[] args) { + try { + Viewer viewer = new Viewer(validateBoardsFromPaths(Main.getResourcePaths())); + 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); + } + } } -- cgit v1.2.3