From eb12a813b07425d410f477c00e195617ee1b6530 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Tue, 3 Mar 2020 16:38:36 +0100 Subject: [PATCH] added debug boolean and get choice method --- src/main/java/webcrawler/Main.java | 12 ++++++++---- src/main/java/webcrawler/WebCrawler.java | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/webcrawler/Main.java b/src/main/java/webcrawler/Main.java index 3940852..18b11a4 100644 --- a/src/main/java/webcrawler/Main.java +++ b/src/main/java/webcrawler/Main.java @@ -13,11 +13,15 @@ public class Main { int amount = Integer.parseInt(scanner.nextLine().trim()); System.out.print("Should the crawler save the links with hits? (Y/N) : "); String choice = scanner.nextLine().toLowerCase().trim(); - boolean save; - if (choice.equals("y")) save = true; - else if (choice.equals("n")) save = false; - else save = false; + boolean save = getChoice(choice); + + System.out.print("Do you want to enable debug mode? (Y/N) : "); WebCrawler crawler = new WebCrawler(amount,save); crawler.search(startUrl,word); } + + private static boolean getChoice(String choice) { + if (choice.trim().toLowerCase().equals("y")) return true; + else return false; + } } diff --git a/src/main/java/webcrawler/WebCrawler.java b/src/main/java/webcrawler/WebCrawler.java index e637739..6d8c5a5 100644 --- a/src/main/java/webcrawler/WebCrawler.java +++ b/src/main/java/webcrawler/WebCrawler.java @@ -11,6 +11,7 @@ public class WebCrawler { private int amountFound = 0; private int successPages = 0; private boolean shouldSaveHitLinks; + private boolean debug; /** * creates a new WebCrawler object with standard values @@ -33,12 +34,17 @@ public class WebCrawler { * @param shouldSaveHitLinks if the crawler should save the links that have one or more hits */ public WebCrawler(int maxPages, boolean shouldSaveHitLinks) { + this(maxPages,shouldSaveHitLinks,false); + } + + public WebCrawler(int maxPages, boolean shouldSaveHitLinks, boolean debug) { this.amountOfPages = maxPages; this.shouldSaveHitLinks = shouldSaveHitLinks; this.pagesVisited = new HashSet<>(); this.pagesPending = new LinkedList<>(); this.resultPages = new ArrayList<>(); this.urlHits = new HashMap<>(); + this.debug = debug; } @@ -132,6 +138,14 @@ public class WebCrawler { return amountFound; } + public boolean usesDebug() { + return debug; + } + + public void setDebug(boolean debug) { + this.debug = debug; + } + /** * clears the crawler */