altoslib: Keep time series in AltosFlightSeries array sorted
authorKeith Packard <keithp@keithp.com>
Mon, 12 Jun 2017 05:47:02 +0000 (22:47 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 12 Jun 2017 05:54:22 +0000 (22:54 -0700)
This makes using the graph way easier.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosFlightSeries.java
altoslib/AltosTimeSeries.java

index 315e0a4..5223a5b 100644 (file)
@@ -118,6 +118,12 @@ public class AltosFlightSeries extends AltosDataListener {
        }
 
        public void add_series(AltosTimeSeries s) {
+               for (int e = 0; e < series.size(); e++) {
+                       if (s.compareTo(series.get(e)) < 0){
+                               series.add(e, s);
+                               return;
+                       }
+               }
                series.add(s);
        }
 
index db33faf..5cf46c9 100644 (file)
@@ -16,11 +16,15 @@ package org.altusmetrum.altoslib_11;
 
 import java.util.*;
 
-public class AltosTimeSeries implements Iterable<AltosTimeValue> {
+public class AltosTimeSeries implements Iterable<AltosTimeValue>, Comparable<AltosTimeSeries> {
        public String                   label;
        public AltosUnits               units;
        ArrayList<AltosTimeValue>       values;
 
+       public int compareTo(AltosTimeSeries other) {
+               return label.compareTo(other.label);
+       }
+
        public void add(AltosTimeValue tv) {
                values.add(tv);
        }