diff --git a/src/main/java/armameeldoparti/controllers/AnchoragesController.java b/src/main/java/armameeldoparti/controllers/AnchoragesController.java index ebd831a..90a6ed6 100644 --- a/src/main/java/armameeldoparti/controllers/AnchoragesController.java +++ b/src/main/java/armameeldoparti/controllers/AnchoragesController.java @@ -262,23 +262,19 @@ private void updateTextArea() { view.getTextArea() .append("ANCLAJE " + (anchorageNumber + 1) + System.lineSeparator()); - List anchoredPlayers = CommonFields.getPlayersSets() - .entrySet() - .stream() - .flatMap( - playersSet -> playersSet.getValue() - .stream() - .filter( - player -> player.getAnchorageNumber() == (anchorageNumber + 1) - ) - ) - .sorted(Comparator.comparing(player -> player.getPosition() - .ordinal())) - .toList(); - - for (Player player : anchoredPlayers) { + List anchorage = CommonFields.getPlayersSets() + .entrySet() + .stream() + .flatMap(players -> players.getValue() + .stream() + .filter(player -> player.getAnchorageNumber() == anchorageNumber + 1)) + .sorted(Comparator.comparing(player -> player.getPosition() + .ordinal())) + .toList(); + + for (Player player : anchorage) { view.getTextArea() - .append((anchoredPlayers.indexOf(player) + 1) + ". " + player.getName() + System.lineSeparator()); + .append((anchorage.indexOf(player) + 1) + ". " + player.getName() + System.lineSeparator()); } if ((anchorageNumber + 1) != anchoragesAmount) { @@ -341,7 +337,7 @@ private void clearAnchorages() { /** * Deletes a specific anchorage. * - *

The players that have the specified anchorage, now will have anchorage number 0. If the anchorage number to delete is not the last one, then + *

The players that have the specified anchorage now will have anchorage number 0. If the anchorage number to delete is not the last one, then * the remaining players (from {@code anchorageToDelete + 1} to {@code anchoragesAmount}) will have their anchorage number decreased by 1. * * @param anchorageToDelete Anchorage number to delete. diff --git a/src/main/java/armameeldoparti/controllers/ResultsController.java b/src/main/java/armameeldoparti/controllers/ResultsController.java index c9a0d9e..6c790b1 100644 --- a/src/main/java/armameeldoparti/controllers/ResultsController.java +++ b/src/main/java/armameeldoparti/controllers/ResultsController.java @@ -233,24 +233,24 @@ private void fillTableFields() { table.setValueAt("EQUIPO " + (teamIndex + 1), 0, teamIndex + 1); } - for (int rowIndex = 1; rowIndex < rowCount; rowIndex++) { + for (int row = 1; row < rowCount; row++) { table.setValueAt( positionsMap.get( - switch (rowIndex) { + switch (row) { case 1 -> Position.CENTRAL_DEFENDER; case 2, 3 -> Position.LATERAL_DEFENDER; case 4, 5 -> Position.MIDFIELDER; default -> Position.FORWARD; } ), - rowIndex, + row, 0 ); } if (CommonFields.getDistribution() == Constants.MIX_BY_SKILL_POINTS) { - for (int colIndex = 0; colIndex < teams.size(); colIndex++) { - table.setValueAt(colIndex == 0 ? positionsMap.get(Position.GOALKEEPER) : "PuntuaciĆ³n del equipo", table.getRowCount() + colIndex - 2, 0); + for (int column = 0; column < teams.size(); column++) { + table.setValueAt(column == 0 ? positionsMap.get(Position.GOALKEEPER) : "PuntuaciĆ³n del equipo", table.getRowCount() + column - 2, 0); } } else { table.setValueAt(positionsMap.get(Position.GOALKEEPER), table.getRowCount() - 1, 0); diff --git a/src/main/java/armameeldoparti/controllers/SkillPointsInputController.java b/src/main/java/armameeldoparti/controllers/SkillPointsInputController.java index 1de6a91..5238d7c 100644 --- a/src/main/java/armameeldoparti/controllers/SkillPointsInputController.java +++ b/src/main/java/armameeldoparti/controllers/SkillPointsInputController.java @@ -1,6 +1,5 @@ package armameeldoparti.controllers; -import java.util.Arrays; import armameeldoparti.models.Position; import armameeldoparti.models.ProgramView; import armameeldoparti.utils.common.CommonFields; @@ -70,13 +69,14 @@ public void backButtonEvent() { * Updates the players name labels. */ public void updateNameLabels() { - Arrays.asList(Position.values()) - .forEach(position -> CommonFields.getPlayersSets() - .get(position) - .forEach(player -> view.getLabelsMap() - .get(view.getSpinnersMap() - .get(player)) - .setText(player.getName()))); + for (Position position : Position.values()) { + CommonFields.getPlayersSets() + .get(position) + .forEach(player -> view.getLabelsMap() + .get(view.getSpinnersMap() + .get(player)) + .setText(player.getName())); + } view.pack(); } diff --git a/src/main/java/armameeldoparti/utils/common/custom/graphical/CustomTable.java b/src/main/java/armameeldoparti/utils/common/custom/graphical/CustomTable.java index 9899eb8..ef74b24 100644 --- a/src/main/java/armameeldoparti/utils/common/custom/graphical/CustomTable.java +++ b/src/main/java/armameeldoparti/utils/common/custom/graphical/CustomTable.java @@ -10,7 +10,6 @@ import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellRenderer; /** * Custom table class. @@ -44,30 +43,23 @@ public CustomTable(int rows, int columns) { * Adjusts the cells size to fit the biggest content shown in the table. */ public void adjustCells() { - int totalColumns = getColumnCount(); - int totalRows = getRowCount(); int maxCellWidth = 0; int maxCellHeight = 0; - for (int row = 0; row < totalRows; row++) { - for (int column = 0; column < totalColumns; column++) { - TableCellRenderer cellRenderer = getCellRenderer(row, column); + for (int row = 0; row < getRowCount(); row++) { + for (int column = 0; column < getColumnCount(); column++) { + Component cellComponent = prepareRenderer(getCellRenderer(row, column), row, column); - Component cellComponent = prepareRenderer(cellRenderer, row, column); - - int cellWidth = cellComponent.getPreferredSize().width + getIntercellSpacing().width; - int cellHeight = cellComponent.getPreferredSize().height + getIntercellSpacing().width; - - maxCellWidth = Math.max(maxCellWidth, cellWidth); - maxCellHeight = Math.max(maxCellHeight, cellHeight); + maxCellWidth = Math.max(maxCellWidth, cellComponent.getPreferredSize().width + getIntercellSpacing().width); + maxCellHeight = Math.max(maxCellHeight, cellComponent.getPreferredSize().height + getIntercellSpacing().height); } } - for (int row = 0; row < totalRows; row++) { + for (int row = 0; row < getRowCount(); row++) { setRowHeight(row, maxCellHeight); } - for (int column = 0; column < totalColumns; column++) { + for (int column = 0; column < getColumnCount(); column++) { getColumnModel().getColumn(column) .setPreferredWidth(maxCellWidth); } diff --git a/src/main/java/armameeldoparti/utils/mixers/BySkillPointsMixer.java b/src/main/java/armameeldoparti/utils/mixers/BySkillPointsMixer.java index 804f61d..bd4b282 100644 --- a/src/main/java/armameeldoparti/utils/mixers/BySkillPointsMixer.java +++ b/src/main/java/armameeldoparti/utils/mixers/BySkillPointsMixer.java @@ -97,12 +97,10 @@ public List withoutAnchorages(List teams) { */ @Override public List withAnchorages(List teams) { - List> anchoredPlayers = CommonFunctions.getAnchoredPlayers(); - - for (List anchoredPlayersSet : anchoredPlayers) { + for (List anchorage : CommonFunctions.getAnchoredPlayers()) { teams.sort(comparingInt(Team::getTeamSkill)); - for (Player player : anchoredPlayersSet) { + for (Player player : anchorage) { player.setTeamNumber(teams.get(0) .getTeamNumber()); @@ -123,16 +121,16 @@ public List withAnchorages(List teams) { remainingPlayers.sort(comparingInt(List::size)); - for (List playersSet : remainingPlayers) { - playersSet.sort(comparingInt(Player::getSkillPoints).reversed()); + for (List players : remainingPlayers) { + players.sort(comparingInt(Player::getSkillPoints).reversed()); - if (playersSet.size() == 4) { + if (players.size() == 4) { teams.sort(comparingInt(Team::getTeamSkill)); - distributeSubsets(teams, playersSet, playersSet.get(0) + distributeSubsets(teams, players, players.get(0) .getPosition()); } else { - for (Player player : playersSet) { + for (Player player : players) { teams.sort(comparingInt(Team::getTeamSkill)); int teamNumber = 0; @@ -169,9 +167,7 @@ public List withAnchorages(List teams) { private void distributeSubsets(List teams, List playersSet, Position position) { List> playersSubsets = new ArrayList<>(); - int currentPositionPlayersPerTeam = playersSet.size() / 2; - - for (int playerIndex = 0; playerIndex < currentPositionPlayersPerTeam; playerIndex++) { + for (int playerIndex = 0; playerIndex < playersSet.size() / 2; playerIndex++) { playersSubsets.add(Arrays.asList(playersSet.get(playerIndex), playersSet.get(playersSet.size() - 1 - playerIndex))); } diff --git a/src/main/java/armameeldoparti/utils/mixers/RandomMixer.java b/src/main/java/armameeldoparti/utils/mixers/RandomMixer.java index d5438bf..6d3f678 100644 --- a/src/main/java/armameeldoparti/utils/mixers/RandomMixer.java +++ b/src/main/java/armameeldoparti/utils/mixers/RandomMixer.java @@ -10,7 +10,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Random; import java.util.function.Predicate; @@ -56,36 +55,38 @@ public RandomMixer() { public List withoutAnchorages(List teams) { shuffleTeamNumbers(teams.size()); - Map> playersSets = CommonFields.getPlayersSets(); - Map> randomTeam1PlayersMap = teams.get(randomTeam1) - .getTeamPlayers(); - Map> randomTeam2PlayersMap = teams.get(randomTeam2) - .getTeamPlayers(); - for (Position position : Position.values()) { - List playersAtPosition = new ArrayList<>(playersSets.get(position)); + List playersAtPosition = new ArrayList<>(CommonFields.getPlayersSets() + .get(position)); Collections.shuffle(playersAtPosition); - randomTeam1PlayersMap.get(position) - .addAll(playersAtPosition.subList(0, playersAtPosition.size() / teams.size())); + teams.get(randomTeam1) + .getTeamPlayers() + .get(position) + .addAll(playersAtPosition.subList(0, playersAtPosition.size() / teams.size())); } - randomTeam1PlayersMap.values() - .stream() - .flatMap(List::stream) - .forEach(player -> player.setTeamNumber(randomTeam1 + 1)); + teams.get(randomTeam1) + .getTeamPlayers() + .values() + .stream() + .flatMap(List::stream) + .forEach(player -> player.setTeamNumber(randomTeam1 + 1)); - playersSets.values() - .stream() - .flatMap(List::stream) - .filter(player -> player.getTeamNumber() == 0) - .forEach(player -> { - randomTeam2PlayersMap.get(player.getPosition()) - .add(player); + CommonFields.getPlayersSets() + .values() + .stream() + .flatMap(List::stream) + .filter(player -> player.getTeamNumber() == 0) + .forEach(player -> { + teams.get(randomTeam2) + .getTeamPlayers() + .get(player.getPosition()) + .add(player); - player.setTeamNumber(randomTeam2 + 1); - }); + player.setTeamNumber(randomTeam2 + 1); + }); return teams; } @@ -104,23 +105,20 @@ public List withoutAnchorages(List teams) { */ @Override public List withAnchorages(List teams) { - List> anchorages = CommonFunctions.getAnchoredPlayers(); - - for (List anchorage : anchorages) { + for (List anchorage : CommonFunctions.getAnchoredPlayers()) { int teamNumber = getAvailableTeam(teams, team -> anchorageCanBeAdded(team, anchorage)); if (teamNumber == -1) { CommonFunctions.exitProgram(Error.ERROR_INTERNAL); } - Map> randomTeamPlayersMap = teams.get(teamNumber) - .getTeamPlayers(); - for (Player player : anchorage) { player.setTeamNumber(teamNumber + 1); - randomTeamPlayersMap.get(player.getPosition()) - .add(player); + teams.get(teamNumber) + .getTeamPlayers() + .get(player.getPosition()) + .add(player); } } diff --git a/src/main/java/armameeldoparti/views/NamesInputView.java b/src/main/java/armameeldoparti/views/NamesInputView.java index e9994c5..50e1879 100644 --- a/src/main/java/armameeldoparti/views/NamesInputView.java +++ b/src/main/java/armameeldoparti/views/NamesInputView.java @@ -14,7 +14,6 @@ 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; @@ -148,12 +147,13 @@ private void addAnchoragesCheckbox() { * Builds, stores and configures each position text fields. */ private void addTextFields() { - Arrays.asList(Position.values()) - .forEach(position -> textFieldsMap.get(position) - .addAll(IntStream.range(0, CommonFields.getPlayersAmountMap() - .get(position) * 2) - .mapToObj(i -> new CustomTextField()) - .toList())); + for (Position position : Position.values()) { + textFieldsMap.get(position) + .addAll(IntStream.range(0, CommonFields.getPlayersAmountMap() + .get(position) * 2) + .mapToObj(i -> new CustomTextField()) + .toList()); + } } /** diff --git a/src/main/java/armameeldoparti/views/SkillPointsInputView.java b/src/main/java/armameeldoparti/views/SkillPointsInputView.java index 104e87a..4302727 100644 --- a/src/main/java/armameeldoparti/views/SkillPointsInputView.java +++ b/src/main/java/armameeldoparti/views/SkillPointsInputView.java @@ -87,13 +87,13 @@ private void addSpinners() { .get(position)), SwingConstants.CENTER), CommonFunctions.buildMigLayoutConstraints(Constants.MIG_LAYOUT_GROW, Constants.MIG_LAYOUT_SPAN)); - List playersSet = new ArrayList<>(CommonFields.getPlayersSets() - .get(position)); + List players = new ArrayList<>(CommonFields.getPlayersSets() + .get(position)); - playersSet.sort(Comparator.comparing(player -> player.getPosition() - .ordinal())); + players.sort(Comparator.comparing(player -> player.getPosition() + .ordinal())); - for (Player player : playersSet) { + for (Player player : players) { spinnersMap.put(player, new CustomSpinner(new SpinnerNumberModel(Constants.SKILL_INI, Constants.SKILL_MIN, Constants.SKILL_MAX, @@ -102,7 +102,7 @@ private void addSpinners() { labelsMap.put(spinnersMap.get(player), new JLabel(player.getName())); masterPanel.add(labelsMap.get(spinnersMap.get(player)), Constants.MIG_LAYOUT_PUSHX); - masterPanel.add(spinnersMap.get(player), playersSet.indexOf(player) % 2 != 0 ? Constants.MIG_LAYOUT_WRAP : null); + masterPanel.add(spinnersMap.get(player), players.indexOf(player) % 2 != 0 ? Constants.MIG_LAYOUT_WRAP : null); } } }