package strategy; import model.Paper; import java.util.ArrayList; import java.util.List; import java.util.Random; public abstract class AbstractCrawlerStrategy implements CrawlerStrategy { protected Random random = new Random(); @Override public List crawl(String url, int count) throws Exception { List papers = new ArrayList<>(); papers.addAll(fetchPapers(url, count)); return papers; } protected abstract List fetchPapers(String url, int count) throws Exception; protected void addDelay(int minMs, int maxMs) { try { int delay = minMs + random.nextInt(maxMs - minMs + 1); Thread.sleep(delay); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }