Sort on source stage for simultaneous events

-- if only one of the events has a source, the other one goes first.
-- if both have sources, lower (numerically higher) stage goes first.
This commit is contained in:
JoePfeiffer 2022-11-08 13:30:21 -07:00
parent 9f06b98bd5
commit d74adf676f

View File

@ -146,15 +146,33 @@ public class FlightEvent implements Comparable<FlightEvent> {
/**
* Compares this event to another event depending on the event time. Secondary
* sorting is performed on stages; lower (numerically higher) stage first. Tertiary
* sorting is performed based on the event type ordinal.
*/
@Override
public int compareTo(FlightEvent o) {
// first, sort on time
if (this.time < o.time)
return -1;
if (this.time > o.time)
return 1;
// second, sort on stage presence. Events with no source go first
if ((this.getSource() == null) && (o.getSource() != null))
return -1;
if ((this.getSource() != null) && (o.getSource() == null))
return 1;
// third, sort on stage order. Bigger stage number goes first
if ((this.getSource() != null) && (o.getSource() != null)) {
if (this.getSource().getStageNumber() > o.getSource().getStageNumber())
return -1;
if (this.getSource().getStageNumber() < o.getSource().getStageNumber())
return 1;
}
// finally, sort on event type
return this.type.ordinal() - o.type.ordinal();
}