Skip to content

Commit

Permalink
#1909 fix initial sorting on player group (#1947)
Browse files Browse the repository at this point in the history
* #1909 fix initial sorting on player group

* release_notes.md add translator
  • Loading branch information
wsbrenk authored Nov 20, 2023
1 parent 4a5ed34 commit 4604d20
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 47 deletions.
13 changes: 2 additions & 11 deletions src/main/java/core/gui/comp/entry/RatingTableEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,9 @@ public final void clear() {
}

public final int compareTo(@NotNull IHOTableEntry obj) {
if (obj instanceof RatingTableEntry) {
final RatingTableEntry entry = (RatingTableEntry) obj;

if (getRating() < entry.getRating()) {
return -1;
} else if (getRating() > entry.getRating()) {
return 1;
} else {
return 0;
}
if (obj instanceof RatingTableEntry entry) {
return Float.compare(getRating(), entry.getRating());
}

return 0;
}

Expand Down
62 changes: 30 additions & 32 deletions src/main/java/core/gui/comp/entry/SmilieEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import core.model.HOVerwaltung;
import core.model.player.MatchRoleID;
import core.model.player.Player;
import core.util.StringUtils;
import org.jetbrains.annotations.NotNull;

import javax.swing.SwingConstants;
Expand All @@ -17,10 +18,10 @@
public class SmilieEntry extends DoubleLabelEntries {
//~ Instance fields ----------------------------------------------------------------------------

private ColorLabelEntry manuell = new ColorLabelEntry("", ColorLabelEntry.FG_STANDARD,
private final ColorLabelEntry manuell = new ColorLabelEntry("", ColorLabelEntry.FG_STANDARD,
ColorLabelEntry.BG_STANDARD,
SwingConstants.RIGHT);
private ColorLabelEntry team = new ColorLabelEntry("", ColorLabelEntry.FG_STANDARD,
private final ColorLabelEntry team = new ColorLabelEntry("", ColorLabelEntry.FG_STANDARD,
ColorLabelEntry.BG_STANDARD,
SwingConstants.LEFT);
private Player player;
Expand All @@ -46,43 +47,40 @@ public final Player getPlayer() {

@Override
public final int compareTo(@NotNull IHOTableEntry obj) {
if (obj instanceof SmilieEntry) {
final SmilieEntry entry = (SmilieEntry) obj;
if (obj instanceof SmilieEntry entry) {

if ((entry.getPlayer() != null) && (getPlayer() != null)) {
int ergebnis = 0;

//Beide null -> Der ManuelleSmilie entscheidet
if (((entry.getPlayer().getTeamGroup() == null)
|| entry.getPlayer().getTeamGroup().equals(""))
&& ((getPlayer().getTeamGroup() == null)
|| getPlayer().getTeamGroup().equals(""))) {
} else if ((entry.getPlayer().getTeamGroup() == null)
|| entry.getPlayer().getTeamGroup().equals("")) {
ergebnis = 1;
} else if ((getPlayer().getTeamGroup() == null)
|| getPlayer().getTeamGroup().equals("")) {
ergebnis = -1;
} else {
ergebnis = entry.getPlayer().getTeamGroup().compareTo(getPlayer()
.getTeamGroup());
int result = 0;
var thisGroup = this.getPlayer().getTeamGroup();
var entryGroup = entry.getPlayer().getTeamGroup();
if (!StringUtils.isEmpty(thisGroup)){
if ( !StringUtils.isEmpty(entryGroup )){
result = thisGroup.compareTo(entryGroup);
}
else {
return -1;
}
}
else if ( !StringUtils.isEmpty(entryGroup )){
return 1;
}

// if equal check lineup
if (ergebnis == 0) {
if (result == 0) {
var team = HOVerwaltung.instance().getModel().getCurrentLineupTeam();
if (team == null) return 0;
final MatchRoleID entrySort = team.getLineup().getPositionByPlayerId(entry.getPlayer().getPlayerID());
final MatchRoleID sort = team.getLineup().getPositionByPlayerId(getPlayer().getPlayerID());
if ((sort == null) && (entrySort == null)) {
ergebnis = 0;
} else if (sort == null) {
ergebnis = -1;
} else if (entrySort == null) {
ergebnis = 1;
} else ergebnis = Integer.compare(entrySort.getSortId(), sort.getSortId());
if (sort != null) {
if (entrySort != null) {
result = Integer.compare(entrySort.getSortId(), sort.getSortId()); // inverse direction (Keeper is top)
} else {
return 1;
}
} else if (entrySort != null) {
return -1;
}
}
return ergebnis;
return result;
}
}
return 0;
Expand All @@ -91,13 +89,13 @@ public final int compareTo(@NotNull IHOTableEntry obj) {
@Override
public final void updateComponent() {
if (player != null) {
if ((player.getTeamGroup() != null) && !player.getTeamGroup().equals("")) {
if ((player.getTeamGroup() != null) && !player.getTeamGroup().isEmpty()) {
team.setIcon(GroupTeamFactory.instance().getActiveGroupIcon(player.getTeamGroup()));
} else {
team.clear();
}

if ((player.getInfoSmiley() != null) && !player.getInfoSmiley().equals("")) {
if ((player.getInfoSmiley() != null) && !player.getInfoSmiley().isEmpty()) {
manuell.setIcon(ImageUtilities.getSmileyIcon(player.getInfoSmiley()));
} else {
manuell.clear();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/core/gui/comp/table/TableSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public TableSorter(TableModel tablemodel, int idColumn, int initsortcolumnindex,

private boolean isAscending(TableModel tablemodel, int initsortcolumnindex) {
return tablemodel instanceof HOTableModel &&
((HOTableModel)tablemodel).getPositionInArray(UserColumnFactory.BEST_POSITION) != initsortcolumnindex;
((HOTableModel) tablemodel).getPositionInArray(UserColumnFactory.BEST_POSITION) != initsortcolumnindex &&
((HOTableModel) tablemodel).getPositionInArray(UserColumnFactory.RATING) != initsortcolumnindex;
}

@Override
Expand Down Expand Up @@ -264,7 +265,7 @@ public final int compare(int i, int j) {
final int l = compareRowsByColumn(i, j, integer);

if (l != 0) {
return ascending ? l : (-l);
return ascending ? l : -l;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* fix length of owner notes in players' database table (#1816)
* player avatar image can be reloaded (#1815)
* fix error player download nickname null pointer exception (#1938)
* fix initial sorting by player group (#1909)

### Team Analyzer
* restore size of match prediction dialog box (#1898)
Expand Down Expand Up @@ -42,10 +43,11 @@

## Translations

Reports by Contributors - September 24, 2023 - October 21, 2023
Reports by Contributors - September 24, 2023 - November 20, 2023

* Georgi 10
* Lidegand 3
* sich 3
* wsbrenk 3

Total 16
Total 19

0 comments on commit 4604d20

Please sign in to comment.