Skip to content

Instantly share code, notes, and snippets.

@ethanfu
Created May 8, 2019 01:42
Show Gist options
  • Save ethanfu/d53900d7f1a1ac6be2df947040e68b5b to your computer and use it in GitHub Desktop.
Save ethanfu/d53900d7f1a1ac6be2df947040e68b5b to your computer and use it in GitHub Desktop.
QpsMain
package com.example;
import java.io.*;
import java.util.*;
/**
* User: fuxueliang
* Date: 2019/4/27
* Email: [email protected]
*/
public class QpsMain {
public static void main(String[] args) throws Exception {
long start = System.currentTimeMillis();
File file = new File("/tmp/ss");
if (file.isFile()) {
Map<String, Long> map = normalRead(file);
map.entrySet().stream().sorted(Comparator.comparing(Map.Entry<String,Long>::getValue).reversed().thenComparing(Map.Entry::getKey)).forEach(item ->
System.out.println(item.getValue() + " " + item.getKey() + ""));
}
System.out.println(" time is : " + (System.currentTimeMillis() - start) + " ms");
}
public static Map<String, Long> normalRead(File file) throws Exception {
Map<String, Long> map = new HashMap<>();
try (
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader)) {
String line;
while ((line = bufferedReader.readLine()) != null) {
line = line.replace("\n", "").split("\\|")[0];
Long count = map.get(line);
if (count != null) {
count += 1;
} else {
count = 1L;
}
map.put(line, count);
}
}
return map;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment