From d74adf676f4894a7e9d1891fce34474913bef878 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Tue, 8 Nov 2022 13:30:21 -0700 Subject: [PATCH] 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. --- .../sf/openrocket/simulation/FlightEvent.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/src/net/sf/openrocket/simulation/FlightEvent.java b/core/src/net/sf/openrocket/simulation/FlightEvent.java index b78ad1f3b..e76d45e0b 100644 --- a/core/src/net/sf/openrocket/simulation/FlightEvent.java +++ b/core/src/net/sf/openrocket/simulation/FlightEvent.java @@ -146,15 +146,33 @@ public class FlightEvent implements Comparable { /** * 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(); }