Untitled

unknown
plain_text
2 years ago
2.1 kB
6
Indexable
Never
```public static void solveUseCase4(List<MatchesData> matches, List<DeliveriesData> deliveries) {
Map<String, Double> topEconomyOfBowlers = new HashMap<>();
Map<String, Integer> runsConcededPerBowler = new HashMap<>();
Map<String, Integer> ballsPerBowler = new HashMap<>();

for (DeliveriesData delivery : deliveries) {
if (isDeliveryIn2015(matches, delivery.getMatchId())) {
int balls = ballsPerBowler.getOrDefault(delivery.getBowler(), 0) + 1;
ballsPerBowler.put(delivery.getBowler(), balls);

int totalRuns = Integer.parseInt(delivery.getTotalRuns());
int legByeRuns = Integer.parseInt(delivery.getLegByeRuns());

// removing legBye runs  since these shouldn't affect bowlers economy
int runs = runsConcededPerBowler.getOrDefault(delivery.getBowler(), 0) + (totalRuns - legByeRuns);
runsConcededPerBowler.put(delivery.getBowler(), runs);
}
}

for (String bowler : ballsPerBowler.keySet()) {
int balls = ballsPerBowler.get(bowler);
int runs = runsConcededPerBowler.get(bowler);
double oversCount = balls / 6.0;
double economyRate = runs / oversCount;
topEconomyOfBowlers.put(bowler, economyRate);
}

Set<Map.Entry<String, Double>> entrySet = topEconomyOfBowlers.entrySet();
List<Map.Entry<String, Double>> sortedList = new ArrayList<>(entrySet);
sortedList.sort(Map.Entry.comparingByValue());

System.out.println(sortedList);
//for(Map.Entry<String, Double> entry : sortedList)
}

private static boolean isDeliveryIn2015(List<MatchesData> matches, String matchId) {
for (MatchesData match : matches) {
if (match.getId().equals(matchId) && match.getSeason().equals("2015")) {
return true;
}
}
return false;
}

Solutions.solveUseCase4(new ArrayList<>(matchDict.values()), deliveriesList);

```