mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-08 20:12:23 +00:00
fix: NPE when sorting competitors by tracked position
This commit is contained in:
1 parent
b8a10e7839
commit
9d5536703c
1 file changed
+23
+23
@@ -10,13 +10,16 @@ import java.util.concurrent.ConcurrentMap;
|
||||
import com.sap.sailing.domain.base.Boat;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.util.NaturalComparator;
|
||||
|
||||
public class CompetitorGoalPassingComparator implements Comparator<Map.Entry<Competitor, Boat>> {
|
||||
|
||||
private ConcurrentMap<UUID, Integer> ranking;
|
||||
private final NaturalComparator naturalComparator;
|
||||
|
||||
public CompetitorGoalPassingComparator() {
|
||||
this.ranking = new ConcurrentHashMap<>();
|
||||
this.naturalComparator = new NaturalComparator();
|
||||
}
|
||||
|
||||
public ConcurrentMap<UUID, Integer> updateWith(List<Util.Pair<Long, String>> sortedList) {
|
||||
@@ -34,6 +37,26 @@ public class CompetitorGoalPassingComparator implements Comparator<Map.Entry<Com
|
||||
public int compare(Map.Entry<Competitor, Boat> leftCompetitor, Map.Entry<Competitor, Boat> rightCompetitor) {
|
||||
Integer leftRank = this.ranking.get(leftCompetitor.getKey().getId());
|
||||
Integer rightRank = this.ranking.get(rightCompetitor.getKey().getId());
|
||||
if (leftRank == null && rightRank == null) {
|
||||
//Compare further properties
|
||||
//Sail ID
|
||||
int result = CompetitorSailIdComparator.compare(leftCompetitor.getValue().getSailID(), rightCompetitor.getValue().getSailID(), naturalComparator);
|
||||
if (result == 0) {
|
||||
//Short name
|
||||
result = CompetitorShortNameComparator.compare(leftCompetitor.getKey().getShortName(), rightCompetitor.getKey().getShortName(), naturalComparator);
|
||||
}
|
||||
if (result == 0) {
|
||||
//Competitor name
|
||||
result = naturalComparator.compare(leftCompetitor.getKey().getName(), rightCompetitor.getKey().getName());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (leftRank == null) {
|
||||
return 1;
|
||||
}
|
||||
if (rightRank == null) {
|
||||
return -1;
|
||||
}
|
||||
return leftRank - rightRank;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user