diff --git a/src/main/java/de/pnreichmuth/timekeep_backend/wsto/TeamWSTO.java b/src/main/java/de/pnreichmuth/timekeep_backend/wsto/TeamWSTO.java index f627b2f..848e9fd 100644 --- a/src/main/java/de/pnreichmuth/timekeep_backend/wsto/TeamWSTO.java +++ b/src/main/java/de/pnreichmuth/timekeep_backend/wsto/TeamWSTO.java @@ -4,54 +4,55 @@ import de.pnreichmuth.timekeep_backend.entities.Racer; import de.pnreichmuth.timekeep_backend.entities.Station; import de.pnreichmuth.timekeep_backend.entities.Team; -import java.util.HashMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; public record TeamWSTO(String teamName, boolean firstSemesterTeam, - Map teamMembers, - Map passedStations) { + List teamMembers, + List passedStations) { public TeamWSTO{ Objects.requireNonNull(teamName, "Cannot identify Team without a name"); - teamMembers = Map.copyOf(teamMembers); - passedStations = Map.copyOf(passedStations); + teamMembers = List.copyOf(teamMembers); + passedStations = List.copyOf(passedStations); } public static TeamWSTO of(Team team){ - Map tmpMemberMap = new HashMap<>(); - for(Map.Entry member : team.getMembers().entrySet()){ - tmpMemberMap.put(member.getKey(), RacerWSTO.of(member.getValue())); - } + List tempMemberList = new ArrayList<>(); + team.getMembers().forEach(member -> { + tempMemberList.add(RacerWSTO.of(member)); + }); + + List tempStationList = new ArrayList<>(); + team.getPassedStations().forEach(passedStation -> { + tempStationList.add(StationWSTO.of(passedStation)); + }); - Map tmpStationMap = new HashMap<>(); - for(Map.Entry station : team.getPassedStations().entrySet()){ - tmpStationMap.put(station.getKey(), StationWSTO.of(station.getValue())); - } return new TeamWSTO( team.getTeamName(), team.isFirstSemesterTeam(), - Map.copyOf(tmpMemberMap), - Map.copyOf(tmpStationMap) + List.copyOf(tempMemberList), + List.copyOf(tempStationList) ); } public static Team toEntity(TeamWSTO teamWSTO){ - Map tmpMemberMap = new HashMap<>(); - for(Map.Entry member : teamWSTO.teamMembers().entrySet()){ - tmpMemberMap.put(member.getKey(), RacerWSTO.toEntity(member.getValue())); - } + List tempMemberList = new ArrayList<>(); + teamWSTO.teamMembers().forEach(member -> { + tempMemberList.add(RacerWSTO.toEntity(member)); + }); - Map tmpStationMap = new HashMap<>(); - for (Map.Entry station : teamWSTO.passedStations().entrySet()) { - tmpStationMap.put(station.getKey(), StationWSTO.toEntity(station.getValue())); - } + List tempStationList = new ArrayList<>(); + teamWSTO.passedStations().forEach(passedStation -> { + tempStationList.add(StationWSTO.toEntity(passedStation)); + }); return new Team( teamWSTO.teamName(), teamWSTO.firstSemesterTeam(), - tmpMemberMap, - tmpStationMap + tempMemberList, + tempStationList ); } }