You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
841 B
27 lines
841 B
package com.crawler.factory;
|
|
|
|
import com.crawler.strategy.*;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class StrategyFactory {
|
|
private static final Map<String, CrawlStrategy> strategies = new HashMap<>();
|
|
|
|
static {
|
|
strategies.put("blog", new BlogCrawlStrategy());
|
|
strategies.put("news", new NewsCrawlStrategy());
|
|
strategies.put("jsoup", new JsoupCrawlStrategy());
|
|
}
|
|
|
|
public static CrawlStrategy getStrategy(String strategyName) {
|
|
return strategies.getOrDefault(strategyName.toLowerCase(), new JsoupCrawlStrategy());
|
|
}
|
|
|
|
public static boolean hasStrategy(String strategyName) {
|
|
return strategies.containsKey(strategyName.toLowerCase());
|
|
}
|
|
|
|
public static String[] getAvailableStrategies() {
|
|
return strategies.keySet().toArray(new String[0]);
|
|
}
|
|
}
|
|
|