Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // reading historico_euromillones.csv
- System.out.print("reading historico_euromillones.csv...");
- // FILE not provided, go to https://www.loteriasyapuestas.es/es/euromillones/estadisticas
- String inputFilePath ="/Users/aironman/Documents/historico_euromillones.csv";
- try {
- List<EMPojo> myListEMPojo = processInputFile(inputFilePath) ;
- myListEMPojo.forEach(System.out::println);
- final Comparator<EMPojo> compTotal2017 = (p1, p2) -> Integer.compare( p1.getTotal_2017(), p2.getTotal_2017());
- final Comparator<EMPojo> compTotal2018 = (p1, p2) -> Integer.compare( p1.getTotal_2018(), p2.getTotal_2018());
- long maxSize = 7l;
- System.out.println();
- System.out.print("reading historico_euromillones.csv sorted by total_2017, 7 values...");
- System.out.println();
- myListEMPojo.stream()
- .sorted(compTotal2017.reversed()) // sort from max to min
- .limit(maxSize)
- .forEach(System.out::println);
- System.out.println();
- System.out.print("reading historico_euromillones.csv sorted by total_2018, 7 values...");
- System.out.println();
- myListEMPojo.stream()
- .sorted(compTotal2018.reversed()) // sort from max to min
- .limit(maxSize)
- .forEach(System.out::println);
- } catch (FileNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- private static List<EMPojo> processInputFile(String inputFilePath) throws FileNotFoundException {
- List<EMPojo> inputList = new ArrayList<EMPojo>();
- try{
- File inputF = new File(inputFilePath);
- InputStream inputFS = new FileInputStream(inputF);
- BufferedReader br = new BufferedReader(new InputStreamReader(inputFS));
- // skip the header of the csv
- inputList = br.lines().skip(1).map(mapToItem).collect(Collectors.toList());
- br.close();
- } catch (IOException e) {
- System.out.println("FileNotFoundException or IOException ");
- e.printStackTrace();
- }
- return inputList ;
- }
- private static Function<String, EMPojo> mapToItem = (line) -> {
- String[] p = line.split(COMMA);// a CSV has comma separated lines
- EMPojo item = new EMPojo(Integer.parseInt(p[0]),Integer.parseInt(p[1]),Integer.parseInt(p[2]),Integer.parseInt(p[3]));
- return item;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement