Fargus811 / Competition

0 stars 0 forks source link

Avoid code duplication in repositories #26

Open dorohovichandrey opened 4 years ago

dorohovichandrey commented 4 years ago

Code is identical, difference only in 2 lines:

    @Override
    public List<Sportsman> findByWeight(int weight) {
        List<Sportsman> weightSportsman = new ArrayList<>();
        for (Sportsman sportsman : sportsmanList
        ) {
            if (sportsman.getWeight() == weight) { // DIFFERENCE!!!
                weightSportsman.add(sportsman);
            }
        }
        return weightSportsman;
    }

    @Override
    public List<Sportsman> findByManandWeight(int weight) {
        List<Sportsman> weightSportsman = new ArrayList<>();
        for (Sportsman sportsman : sportsmanList
        ) {
            if (**sportsman.getWeight() == weight && sportsman.getSex() == Sex.MALE**) {  // DIFFERENCE!!!
                weightSportsman.add(sportsman);
            }
        }
        return weightSportsman;
    }
Fargus811 commented 4 years ago

this code isnt working for now