Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.9 kB
2
Indexable
Never
 private static void findOutTheBoundariesbyPlayerInEachVenue(List<Delivery> deliveries, List<Match> matches) {
        Map<String, Venue> theBoundariesByPlayerInEachVenue = new HashMap<>();

        for (Match match : matches) {
            Map<String, Integer> eachPlayerBoundary = new HashMap<>();
            int eachMatchId = Integer.parseInt(match.getId());
            boolean visited = false;
            if (theBoundariesByPlayerInEachVenue.containsKey(match.getCity())) {
                for (Delivery balls : deliveries) {
                    int boundary = Integer.parseInt(balls.getBatsmanRuns());
                    int deliveryMatchId = Integer.parseInt(balls.getMatchId());
                    if (eachMatchId == deliveryMatchId) {
                        if (boundary == 4) {
                            if (eachPlayerBoundary.containsKey(balls.getBatsman())) {
                                int batsManBoundaries = eachPlayerBoundary.get(balls.getBatsman());
                                eachPlayerBoundary.put(balls.getBatsman(), batsManBoundaries + 1);
                            } else {
                                eachPlayerBoundary.put(balls.getBatsman(), 1);
                            }
                        }
                        visited = true;
                    }
                    else if(visited) {
                        theBoundariesByPlayerInEachVenue.put(match.getCity(),eachPlayerBoundary);
                        break;
                    }
                }
            }
            else {
                for (Delivery ball : deliveries) {
                    int boundary = Integer.parseInt(ball.getBatsmanRuns());
                    int matchId = Integer.parseInt(ball.getMatchId());
                    if (eachMatchId == matchId) {
                        if (boundary == 4) {
                            if (eachPlayerBoundary.containsKey(ball.getBatsman())) {
                                int batsManBoundaries = eachPlayerBoundary.get(ball.getBatsman());
                                eachPlayerBoundary.put(ball.getBatsman(), batsManBoundaries + 1);
                            } else {
                                eachPlayerBoundary.put(ball.getBatsman(), 1);
                            }
                            visited = true;
                        }
                    } else if(visited) {
                        theBoundariesByPlayerInEachVenue.put(match.getCity(), eachPlayerBoundary);
                    }
                }
            }
        }
        for (Map.Entry<String, Map<String, Integer>> listOfEachVenueOfEachPlayerBoundary : theBoundariesByPlayerInEachVenue.entrySet()) {
            System.out.print(listOfEachVenueOfEachPlayerBoundary.getKey()+":- ");
            System.out.println(listOfEachVenueOfEachPlayerBoundary.getValue());
            System.out.println();
        }
    }