Untitled
unknown
plain_text
2 years ago
2.3 kB
2
Indexable
Never
private static void findOutAverageWideBallsOfATeamInAllSeason(List<Match> matches, List<Delivery> deliveries) { Map<Integer,Map<String,Venue>> averageWideBallsOfATeamInAllSeason = new HashMap<>(); Map<String,String> eachIdForAParticularYear = new HashMap<>(); for(Match match : matches) { eachIdForAParticularYear.put(match.getId(),match.getSeason()); } //System.out.println(eachIdForAParticularYear); for(Delivery balls : deliveries) { if(averageWideBallsOfATeamInAllSeason.containsKey(Integer.parseInt(eachIdForAParticularYear.get(balls.getMatchId())))) { Map<String,Venue> ans = averageWideBallsOfATeamInAllSeason.get(Integer.parseInt(eachIdForAParticularYear.get(balls.getMatchId()))); if(ans.containsKey(balls.getBowlingTeam())) { Venue ls = ans.get(balls.getBowlingTeam()); ls.setWideRuns(ls.getWideRuns() + Integer.parseInt(balls.getWideRuns())); ls.setTotalBalls(ls.getTotalBalls() + 1); } else { Venue ls = new Venue(); ls.setTotalBalls(1); ls.setWideRuns(Integer.parseInt(balls.getWideRuns())); ans.put(balls.getBowlingTeam(), ls ); } } else { int year = Integer.parseInt(eachIdForAParticularYear.get(balls.getMatchId())); Map<String,Venue> ls = new HashMap<>(); Venue data = new Venue(); data.setWideRuns(Integer.parseInt(balls.getWideRuns())); data.setTotalBalls(1); ls.put(balls.getBowlingTeam(),data); averageWideBallsOfATeamInAllSeason.put(year,ls); } } for(Map.Entry<Integer , Map<String, Venue>> list : averageWideBallsOfATeamInAllSeason.entrySet()) { System.out.print("Season :- " + list.getKey()+" "); for(Map.Entry<String, Venue> list2 : list.getValue().entrySet()) { double balls = list2.getValue().getTotalBalls(); double wideRuns = list2.getValue().getWideRuns(); System.out.println(list2.getKey() + " " + (wideRuns/balls)*100); } System.out.println(); } }