public class Cache
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
kDefaultCapacity
Default cache capacity
|
Constructor and Description |
---|
Cache()
Construct a Cache with the default capacity.
|
Cache(int capacity)
Construct a Cache with the specified capacity.
|
Modifier and Type | Method and Description |
---|---|
java.util.ArrayList<WebPage> |
getPageList()
Return an ordered list of all WebPages in the cache (using the
default ordering).
|
int |
getRequestCount()
Return the number of URL requests received.
|
int |
getUrlFetchCount()
Return the total number of pages fetched from the Internet.
|
void |
processUrls(java.io.Reader instream)
Call
requestPage() for every url in the input stream available at
the provided Reader. |
java.lang.String |
requestPage(java.lang.String url)
Respond to a request for a web page (given the URL).
|
public static final int kDefaultCapacity
public Cache()
public Cache(int capacity)
capacity
- the max number of entries in the cachepublic void processUrls(java.io.Reader instream)
requestPage()
for every url in the input stream available at
the provided Reader. Each url is on a separate line and may include leading or trailing blanks.
Ignore the value returned by requestPage()
.instream
- a Reader for the stream of url requests,public java.lang.String requestPage(java.lang.String url)
url
- the URL of the page to be returnedMalformedURLException
requestCount
for this cache
has been incremented.public java.util.ArrayList<WebPage> getPageList()
public int getRequestCount()
public int getUrlFetchCount()