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());
|
int amount = Integer.parseInt(scanner.nextLine().trim());
|
||||||
System.out.print("Should the crawler save the links with hits? (Y/N) : ");
|
System.out.print("Should the crawler save the links with hits? (Y/N) : ");
|
||||||
String choice = scanner.nextLine().toLowerCase().trim();
|
String choice = scanner.nextLine().toLowerCase().trim();
|
||||||
boolean save;
|
boolean save = getChoice(choice);
|
||||||
if (choice.equals("y")) save = true;
|
|
||||||
else if (choice.equals("n")) save = false;
|
System.out.print("Do you want to enable debug mode? (Y/N) : ");
|
||||||
else save = false;
|
|
||||||
WebCrawler crawler = new WebCrawler(amount,save);
|
WebCrawler crawler = new WebCrawler(amount,save);
|
||||||
crawler.search(startUrl,word);
|
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 amountFound = 0;
|
||||||
private int successPages = 0;
|
private int successPages = 0;
|
||||||
private boolean shouldSaveHitLinks;
|
private boolean shouldSaveHitLinks;
|
||||||
|
private boolean debug;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new WebCrawler object with standard values
|
* 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
|
* @param shouldSaveHitLinks if the crawler should save the links that have one or more hits
|
||||||
*/
|
*/
|
||||||
public WebCrawler(int maxPages, boolean shouldSaveHitLinks) {
|
public WebCrawler(int maxPages, boolean shouldSaveHitLinks) {
|
||||||
|
this(maxPages,shouldSaveHitLinks,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebCrawler(int maxPages, boolean shouldSaveHitLinks, boolean debug) {
|
||||||
this.amountOfPages = maxPages;
|
this.amountOfPages = maxPages;
|
||||||
this.shouldSaveHitLinks = shouldSaveHitLinks;
|
this.shouldSaveHitLinks = shouldSaveHitLinks;
|
||||||
this.pagesVisited = new HashSet<>();
|
this.pagesVisited = new HashSet<>();
|
||||||
this.pagesPending = new LinkedList<>();
|
this.pagesPending = new LinkedList<>();
|
||||||
this.resultPages = new ArrayList<>();
|
this.resultPages = new ArrayList<>();
|
||||||
this.urlHits = new HashMap<>();
|
this.urlHits = new HashMap<>();
|
||||||
|
this.debug = debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -132,6 +138,14 @@ public class WebCrawler {
|
|||||||
return amountFound;
|
return amountFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean usesDebug() {
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDebug(boolean debug) {
|
||||||
|
this.debug = debug;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clears the crawler
|
* clears the crawler
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user