added debug boolean and get choice method
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user