import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class WMStats { private static final String FILE_NAME = "pagecounts-20141029-230000"; private static final String PREFIX = "en "; private static final String DELIMITER = " "; private static final int THRESHOLD = 500; public static void main(String[] args) throws IOException { new WMStats().go(); } public void go() throws IOException { List list = new ArrayList<>(); long start = System.currentTimeMillis(); try (BufferedReader reader = new BufferedReader(new FileReader(FILE_NAME))) { for (String line; (line = reader.readLine()) != null; ) { if (!line.startsWith(PREFIX)) { continue; } String[] parts = line.split(DELIMITER); int count = Integer.parseInt(parts[2]); if (count >= THRESHOLD) { list.add(new NameAndCount(parts[1], count)); } } } Collections.sort(list); System.out.println("Query took " + (System.currentTimeMillis() - start) / 1000f + " seconds"); for (NameAndCount pair : list.subList(0, 9)) { System.out.println(pair.name + " (" + pair.count + ")"); } } class NameAndCount implements Comparable { String name; int count; NameAndCount(String name, int count) { this.name = name; this.count = count; } @Override public int compareTo(NameAndCount other) { return Integer.compare(other.count, count); } } }