Advertisement
aironman

euromillones

Nov 12th, 2018
156
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // reading historico_euromillones.csv
  2. System.out.print("reading historico_euromillones.csv...");
  3. // FILE not provided, go to https://www.loteriasyapuestas.es/es/euromillones/estadisticas
  4. String inputFilePath ="/Users/aironman/Documents/historico_euromillones.csv";
  5.  
  6. try {
  7. List<EMPojo> myListEMPojo = processInputFile(inputFilePath) ;
  8. myListEMPojo.forEach(System.out::println);
  9. final Comparator<EMPojo> compTotal2017 = (p1, p2) -> Integer.compare( p1.getTotal_2017(), p2.getTotal_2017());
  10. final Comparator<EMPojo> compTotal2018 = (p1, p2) -> Integer.compare( p1.getTotal_2018(), p2.getTotal_2018());
  11. long maxSize = 7l;
  12. System.out.println();
  13. System.out.print("reading historico_euromillones.csv sorted by total_2017, 7 values...");
  14. System.out.println();
  15. myListEMPojo.stream()
  16. .sorted(compTotal2017.reversed()) // sort from max to min
  17. .limit(maxSize)
  18. .forEach(System.out::println);
  19.  
  20. System.out.println();
  21. System.out.print("reading historico_euromillones.csv sorted by total_2018, 7 values...");
  22. System.out.println();
  23. myListEMPojo.stream()
  24. .sorted(compTotal2018.reversed()) // sort from max to min
  25. .limit(maxSize)
  26. .forEach(System.out::println);
  27.  
  28. } catch (FileNotFoundException e1) {
  29. // TODO Auto-generated catch block
  30. e1.printStackTrace();
  31. }
  32. }
  33.  
  34. private static List<EMPojo> processInputFile(String inputFilePath) throws FileNotFoundException {
  35. List<EMPojo> inputList = new ArrayList<EMPojo>();
  36. try{
  37. File inputF = new File(inputFilePath);
  38. InputStream inputFS = new FileInputStream(inputF);
  39. BufferedReader br = new BufferedReader(new InputStreamReader(inputFS));
  40. // skip the header of the csv
  41. inputList = br.lines().skip(1).map(mapToItem).collect(Collectors.toList());
  42. br.close();
  43. } catch (IOException e) {
  44. System.out.println("FileNotFoundException or IOException ");
  45. e.printStackTrace();
  46. }
  47. return inputList ;
  48. }
  49.  
  50. private static Function<String, EMPojo> mapToItem = (line) -> {
  51. String[] p = line.split(COMMA);// a CSV has comma separated lines
  52. EMPojo item = new EMPojo(Integer.parseInt(p[0]),Integer.parseInt(p[1]),Integer.parseInt(p[2]),Integer.parseInt(p[3]));
  53. return item;
  54.  
  55. };
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement