@@ -8,19 +8,31 @@ public class SCache {
88 private Map <String , HttpResponse > cacheStore ;
99 HttpRequest request ;
1010
11+ /**
12+ * [SCache description]
13+ */
1114 public SCache () {
1215 // synchronised HasMap prevents data corruption when reading while writing the Map
1316 cacheStore = Collections .synchronizedMap (new HashMap <String , HttpResponse >());
1417 request = new HttpRequest ("GET" , "" , "HTTP/1.1" , "" , "" , 0 );
1518 }
1619
17- // add value to HashMap
20+ /**
21+ * Add the HttpResponse into the HashMap cache with the url as the key.
22+ * @param key The Url
23+ * @param value The HttpResponse
24+ * @return The given value HttpResponse
25+ */
1826 public HttpResponse put (String key , HttpResponse value ) {
1927 System .out .println ("SCACHE: Saved " + key + " to cache." );
2028 return cacheStore .put (key , value );
2129 }
2230
23- // retrieve value from HashMap
31+ /**
32+ * Retrieves the HttpResponse from HashMap cache by looking up the url
33+ * @param key The Url
34+ * @return The Cached HttpResponse
35+ */
2436 public HttpResponse get (String key ) {
2537 System .out .println ("SCACHE: looking for " + key + " in cache." );
2638 HttpResponse value = cacheStore .get (key );
@@ -39,6 +51,12 @@ public HttpResponse get(String key) {
3951 }
4052
4153 // check if response is still valid
54+ /**
55+ * Determine if the Cache HttpResonse is still fresh.
56+ * @param requestURL The key in the cache
57+ * @param response The value in the cache
58+ * @return isValid? as in is the item in the cache fresh?
59+ */
4260 public boolean isValid (String requestURL , HttpResponse response ) {
4361 if (!response .isExpired ()) { // TODO: add command line flag
4462 System .out .println ("SCACHE: response has not expired" );
@@ -67,6 +85,11 @@ public boolean isValid(String requestURL, HttpResponse response) {
6785 // return false;
6886 }
6987
88+ /**
89+ * From a url string get the hostname
90+ * @param url The Url (http://example.com/foo)
91+ * @return The Hostname (example.com)
92+ */
7093 public static String getHost (String url ) {
7194 if (url == null || url .length () <= 0 ) {
7295 return "" ;
@@ -86,6 +109,11 @@ public static String getHost(String url) {
86109 return url .substring (start , end );
87110 }
88111
112+ /**
113+ * From a utl string get the port number
114+ * @param url The Url (http://example.com:50/foo)
115+ * @return The Port number (50)
116+ */
89117 public static int getPort (String url ) {
90118 if (url == null || url .length () <= 0 ) {
91119 return 80 ;
@@ -115,6 +143,11 @@ public static int getPort(String url) {
115143 return Integer .parseInt (url .substring (port , end ));
116144 }
117145
146+ /**
147+ * From a url string get the location
148+ * @param url The Url (http://example.com/foo)
149+ * @return The location (/foo)
150+ */
118151 public static String getLocation (String url ) {
119152 if (url == null || url .length () <= 0 ) {
120153 return "" ;
0 commit comments