From 8a5a43d12d0690096152106ccf658e492353bc69 Mon Sep 17 00:00:00 2001 From: akmsw Date: Tue, 2 Jan 2024 19:32:37 -0300 Subject: [PATCH] enhance text fields creation --- src/main/java/armameeldoparti/Main.java | 5 ++--- .../controllers/NamesInputController.java | 3 +-- .../armameeldoparti/views/NamesInputView.java | 17 ++++++++--------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/armameeldoparti/Main.java b/src/main/java/armameeldoparti/Main.java index efe5970..d353bc5 100644 --- a/src/main/java/armameeldoparti/Main.java +++ b/src/main/java/armameeldoparti/Main.java @@ -32,7 +32,6 @@ import java.util.Map; import java.util.Objects; import java.util.TreeMap; -import java.util.stream.Collectors; import java.util.stream.IntStream; import javax.swing.SwingUtilities; import javax.swing.UIManager; @@ -99,7 +98,7 @@ private static void populatePlayersSets() { .put(position, IntStream.range(0, CommonFields.getPlayersAmountMap() .get(position) * 2) .mapToObj(i -> new Player("", position)) - .collect(Collectors.toList()))); + .toList())); } /** @@ -128,7 +127,7 @@ private static void setPlayersDistribution() { ) { List filteredLines = buff.lines() .filter(line -> line.matches(Constants.REGEX_PDA_DATA_RETRIEVE)) - .collect(Collectors.toList()); + .toList(); IntStream.range(0, filteredLines.size()) .forEach( diff --git a/src/main/java/armameeldoparti/controllers/NamesInputController.java b/src/main/java/armameeldoparti/controllers/NamesInputController.java index 176c07a..af33643 100644 --- a/src/main/java/armameeldoparti/controllers/NamesInputController.java +++ b/src/main/java/armameeldoparti/controllers/NamesInputController.java @@ -12,7 +12,6 @@ import java.util.List; import java.util.Objects; import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.stream.IntStream; import javax.naming.InvalidNameException; import javax.swing.JComboBox; @@ -285,7 +284,7 @@ private void updateTextArea() { .stream() .filter(player -> !player.getName() .equals(""))) - .collect(Collectors.toList()); + .toList(); IntStream.range(0, players.size()) .forEachOrdered(index -> view.getTextArea() diff --git a/src/main/java/armameeldoparti/views/NamesInputView.java b/src/main/java/armameeldoparti/views/NamesInputView.java index 77b3e44..bbc0307 100644 --- a/src/main/java/armameeldoparti/views/NamesInputView.java +++ b/src/main/java/armameeldoparti/views/NamesInputView.java @@ -14,9 +14,11 @@ import armameeldoparti.utils.common.custom.graphical.CustomTextArea; import armameeldoparti.utils.common.custom.graphical.CustomTextField; import java.util.ArrayList; +import java.util.Arrays; import java.util.EnumMap; import java.util.List; import java.util.Map; +import java.util.stream.IntStream; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; @@ -147,15 +149,12 @@ private void addAnchoragesCheckbox() { * Builds, stores and configures each position text fields. */ private void addTextFields() { - for (Position position : Position.values()) { - int totalPlayersInPosition = CommonFields.getPlayersAmountMap() - .get(position) * 2; - - for (int i = 0; i < totalPlayersInPosition; i++) { - textFieldsMap.get(position) - .add(new CustomTextField()); - } - } + Arrays.asList(Position.values()) + .forEach(position -> textFieldsMap.get(position) + .addAll(IntStream.range(0, CommonFields.getPlayersAmountMap() + .get(position) * 2) + .mapToObj(i -> new CustomTextField()) + .toList())); } /**