mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-27 06:17:27 +00:00
RaceMetadataDTO is now comparable
This commit is contained in:
1 parent
ab10dea856
commit
ec922e16c1
2 files changed
+56
-59
No files matched your search
+1
-58
@@ -1,15 +1,11 @@
|
||||
package com.sap.sailing.gwt.ui.shared.dispatch.event;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.sap.sailing.gwt.ui.shared.race.FlagStateDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.race.FleetMetadataDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.race.RaceMetadataDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.race.RaceProgressDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.race.SimpleWindDTO;
|
||||
import com.sap.sse.common.Util;
|
||||
|
||||
public class LiveRaceDTO extends RaceMetadataDTO implements Comparable<LiveRaceDTO> {
|
||||
public class LiveRaceDTO extends RaceMetadataDTO {
|
||||
|
||||
private FlagStateDTO flagState;
|
||||
|
||||
@@ -48,57 +44,4 @@ public class LiveRaceDTO extends RaceMetadataDTO implements Comparable<LiveRaceD
|
||||
public void setProgress(RaceProgressDTO progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LiveRaceDTO o) {
|
||||
Date thisStart = getStart();
|
||||
Date otherStart = o.getStart();
|
||||
if(Util.equalsWithNull(thisStart, otherStart)) {
|
||||
// cases where both start times are == null or equal
|
||||
return compareBySecondaryCriteria(o);
|
||||
}
|
||||
if(thisStart == null) {
|
||||
return 1;
|
||||
}
|
||||
if(otherStart == null) {
|
||||
return -1;
|
||||
}
|
||||
return -thisStart.compareTo(otherStart);
|
||||
}
|
||||
|
||||
private int compareBySecondaryCriteria(LiveRaceDTO o) {
|
||||
String thisRegattaName = getRegattaName();
|
||||
String otherRegattaName = o.getRegattaName();
|
||||
if(thisRegattaName != otherRegattaName) {
|
||||
if(thisRegattaName == null) {
|
||||
return 1;
|
||||
}
|
||||
if(otherRegattaName == null) {
|
||||
return -1;
|
||||
}
|
||||
int compareByRegatta = thisRegattaName.compareTo(otherRegattaName);
|
||||
if(compareByRegatta != 0) {
|
||||
return compareByRegatta;
|
||||
}
|
||||
}
|
||||
int compareByRace = getRaceName().compareTo(o.getRaceName());
|
||||
if(compareByRace != 0) {
|
||||
return compareByRace;
|
||||
}
|
||||
FleetMetadataDTO thisFleet = getFleet();
|
||||
FleetMetadataDTO otherFleet = o.getFleet();
|
||||
if(thisFleet != otherFleet) {
|
||||
if(thisFleet == null) {
|
||||
return 1;
|
||||
}
|
||||
if(otherFleet == null) {
|
||||
return -1;
|
||||
}
|
||||
int compareByFleet = thisFleet.compareTo(otherFleet);
|
||||
if(compareByFleet != 0) {
|
||||
return compareByFleet;
|
||||
}
|
||||
}
|
||||
return getViewState().compareTo(o.getViewState());
|
||||
}
|
||||
}
|
||||
+55
-1
@@ -4,8 +4,9 @@ import java.util.Date;
|
||||
|
||||
import com.google.gwt.user.client.rpc.IsSerializable;
|
||||
import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||
import com.sap.sse.common.Util;
|
||||
|
||||
public class RaceMetadataDTO implements IsSerializable {
|
||||
public class RaceMetadataDTO implements IsSerializable, Comparable<RaceMetadataDTO> {
|
||||
|
||||
public enum RaceViewState {
|
||||
PLANNED { // no start time set
|
||||
@@ -153,4 +154,57 @@ public class RaceMetadataDTO implements IsSerializable {
|
||||
public void setRegattaDisplayName(String regattaDisplayName) {
|
||||
this.regattaDisplayName = regattaDisplayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(RaceMetadataDTO o) {
|
||||
Date thisStart = getStart();
|
||||
Date otherStart = o.getStart();
|
||||
if(Util.equalsWithNull(thisStart, otherStart)) {
|
||||
// cases where both start times are == null or equal
|
||||
return compareBySecondaryCriteria(o);
|
||||
}
|
||||
if(thisStart == null) {
|
||||
return 1;
|
||||
}
|
||||
if(otherStart == null) {
|
||||
return -1;
|
||||
}
|
||||
return -thisStart.compareTo(otherStart);
|
||||
}
|
||||
|
||||
private int compareBySecondaryCriteria(RaceMetadataDTO o) {
|
||||
String thisRegattaName = getRegattaName();
|
||||
String otherRegattaName = o.getRegattaName();
|
||||
if(thisRegattaName != otherRegattaName) {
|
||||
if(thisRegattaName == null) {
|
||||
return 1;
|
||||
}
|
||||
if(otherRegattaName == null) {
|
||||
return -1;
|
||||
}
|
||||
int compareByRegatta = thisRegattaName.compareTo(otherRegattaName);
|
||||
if(compareByRegatta != 0) {
|
||||
return compareByRegatta;
|
||||
}
|
||||
}
|
||||
int compareByRace = getRaceName().compareTo(o.getRaceName());
|
||||
if(compareByRace != 0) {
|
||||
return compareByRace;
|
||||
}
|
||||
FleetMetadataDTO thisFleet = getFleet();
|
||||
FleetMetadataDTO otherFleet = o.getFleet();
|
||||
if(thisFleet != otherFleet) {
|
||||
if(thisFleet == null) {
|
||||
return 1;
|
||||
}
|
||||
if(otherFleet == null) {
|
||||
return -1;
|
||||
}
|
||||
int compareByFleet = thisFleet.compareTo(otherFleet);
|
||||
if(compareByFleet != 0) {
|
||||
return compareByFleet;
|
||||
}
|
||||
}
|
||||
return getViewState().compareTo(o.getViewState());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user