forked from bharathpalaksha/WebsiteAnalyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebsiteAnalyzer.java
More file actions
executable file
·54 lines (39 loc) · 1.03 KB
/
WebsiteAnalyzer.java
File metadata and controls
executable file
·54 lines (39 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package sample;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class WebsiteAnalyzer {
List<PageObject> pageAccess = new LinkedList<PageObject>();
public void reportPageAccess(String pageUri) {
boolean found = false;
for(PageObject page : pageAccess) {
if(page.getUri().equals(pageUri)) {
found = true;
page.setAccessCount(page.getAccessCount()+1);
break;
}
}
if(!found) {
PageObject newPage = new PageObject();
newPage.setUri(pageUri);
newPage.setAccessCount(1);
pageAccess.add(newPage);
}
Collections.sort(pageAccess, new PageAccessComparator());
}
public List<String> getTopNpages(int n) {
List<String> topNpages = new ArrayList<String>();
int maxN = n;
if( n > pageAccess.size()) {
maxN = pageAccess.size();
}
for(int i=0;i<maxN;i++) {
topNpages.add(pageAccess.get(i).getUri());
}
return topNpages;
}
}