package nl.connectedit.swiss.mapper; import java.util.Iterator; import java.util.List; import lombok.RequiredArgsConstructor; import nl.connectedit.swiss.dto.StandingsDto; import nl.connectedit.swiss.dto.StandingsEntry; import nl.connectedit.swiss.dto.StandingsEntryDto; import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor public class StandingsMapper { private final TeamMapper teamMapper; public StandingsDto toDto(List standings) { var standingsDto = new StandingsDto(); Long position = 1L; for (Iterator i = standings.iterator(); i.hasNext(); position++ ) { standingsDto.getEntries().add(toDto(i.next(), position)); } return standingsDto; } private StandingsEntryDto toDto(StandingsEntry standingsEntry, Long position) { var standingsEntryDto = new StandingsEntryDto(); standingsEntryDto.setPosition(position); standingsEntryDto.setTeam(teamMapper.toDto(standingsEntry.getTeam())); standingsEntryDto.setPlayed(standingsEntry.getPlayed()); standingsEntryDto.setWon(standingsEntry.getWon()); standingsEntryDto.setLost(standingsEntry.getLost()); standingsEntryDto.setPoints(standingsEntry.getPoints()); standingsEntryDto.setGamesWon(standingsEntry.getGamesWon()); standingsEntryDto.setGamesLost(standingsEntry.getGamesLost()); standingsEntryDto.setPointsWon(standingsEntry.getPointsWon()); standingsEntryDto.setPointsLost(standingsEntry.getPointsLost()); return standingsEntryDto; } }