1 import java.io.*;
 2 import java.util.*;
 3 import java.util.Map.Entry;
 4 import java.util.regex.*;
 5
 6 public class WfReader {
 7     public static void main(String[] args) throws IOException {
 8         BufferedReader br = new BufferedReader(new FileReader(args[0]));
 9         Map<String, Integer> urls = new HashMap<String, Integer>();
10         String linha;
11         Pattern p = Pattern.compile("GET /ongoing/When/\\d{3}x/(\\d{4}/\\d\\d/\\d\\d/[^ .]+) ");
12         Matcher m = p.matcher("");
13         
14         while((linha = br.readLine()) != null) {
15             m.reset(linha);
16             if(m.find()) {
17                 String url = m.group(1);
18                 Integer n = urls.get(url);
19                 urls.put(url, n == null ? 1 : n + 1);
20             }
21         }
22         List<Entry<String,Integer>> s = new ArrayList<Entry<String, Integer>>(urls.entrySet());
23         Collections.sort(s, new Comparator<Entry<String, Integer>>() {
24             public int compare(Entry<String, Integer> o1,
25                     Entry<String, Integer> o2) {
26                 return o2.getValue() - o1.getValue();
27             }
28         });
29         
30         for(int i = 0; i != 10; ++i) 
31             System.out.println(s.get(i).getKey() + " " + s.get(i).getValue());
32     }
33 }