Skip to content

Commit

Permalink
enhance text area update
Browse files Browse the repository at this point in the history
  • Loading branch information
akmsw committed Jan 3, 2024
1 parent 660c942 commit cfa4ff3
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions src/main/java/armameeldoparti/controllers/AnchoragesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import armameeldoparti.utils.common.Constants;
import armameeldoparti.views.AnchoragesView;
import java.awt.Component;
import java.util.Comparator;
import java.util.List;
import java.util.stream.IntStream;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;

Expand Down Expand Up @@ -260,36 +262,31 @@ private void updateTextArea() {
view.getTextArea()
.setText("");

var wrapper = new Object() {
private int anchorageNumber;
private int counter = 1;
};

for (wrapper.anchorageNumber = 1; wrapper.anchorageNumber <= anchoragesAmount; wrapper.anchorageNumber++) {
view.getTextArea()
.append("ANCLAJE " + wrapper.anchorageNumber + System.lineSeparator());

CommonFields.getPlayersSets()
.forEach(
(key, value) -> value.stream()
.filter(player -> player.getAnchorageNumber() == wrapper.anchorageNumber)
.forEach(
player -> {
view.getTextArea()
.append(wrapper.counter + ". " + player.getName() + System.lineSeparator());

wrapper.counter++;
}
)
);

if (wrapper.anchorageNumber != anchoragesAmount) {
view.getTextArea()
.append(System.lineSeparator());
}

wrapper.counter = 1;
}
IntStream.range(0, anchoragesAmount)
.forEach(i -> {
view.getTextArea()
.append("ANCLAJE " + (i + 1) + System.lineSeparator());

List<Player> anchoredPlayers = CommonFields.getPlayersSets()
.entrySet()
.stream()
.flatMap(playersSet -> playersSet.getValue()
.stream()
.filter(player -> player.getAnchorageNumber() == (i + 1)))
.sorted(Comparator.comparing(player -> player.getPosition()
.ordinal()))
.toList();

for (Player player : anchoredPlayers) {
view.getTextArea()
.append((anchoredPlayers.indexOf(player) + 1) + ". " + player.getName() + System.lineSeparator());
}

if ((i + 1) != anchoragesAmount) {
view.getTextArea()
.append(System.lineSeparator());
}
});
}

/**
Expand Down

0 comments on commit cfa4ff3

Please sign in to comment.