From 9e7fd80181e6881baaf205f3aaeb3ff26f6fcb57 Mon Sep 17 00:00:00 2001 From: akmsw Date: Mon, 1 Jan 2024 18:32:41 -0300 Subject: [PATCH] enhance empty players creation --- src/main/java/armameeldoparti/Main.java | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/java/armameeldoparti/Main.java b/src/main/java/armameeldoparti/Main.java index e5af5bb..0ad59db 100644 --- a/src/main/java/armameeldoparti/Main.java +++ b/src/main/java/armameeldoparti/Main.java @@ -26,7 +26,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.util.ArrayList; +import java.util.Arrays; import java.util.EnumMap; import java.util.List; import java.util.Map; @@ -94,20 +94,14 @@ public static void main(String[] args) { * Populates the players sets with empty players. */ private static void populatePlayersSets() { - for (Position position : Position.values()) { - List playersSet = new ArrayList<>(); + Arrays.stream(Position.values()) + .forEach(position -> CommonFields.getPlayersSets() + .put(position, IntStream.range(0, CommonFields.getPlayersAmountMap() + .get(position) * 2) + .mapToObj(i -> new Player("", position)) + .collect(Collectors.toList()))); +} - int totalPlayersInPosition = CommonFields.getPlayersAmountMap() - .get(position) * 2; - - for (int i = 0; i < totalPlayersInPosition; i++) { - playersSet.add(new Player("", position)); - } - - CommonFields.getPlayersSets() - .put(position, playersSet); - } - } /** * Gets the number of players for each position per team using regular expressions.