+import org.altusmetrum.altoslib_13.*;
+
+class SavedState {
+ long received_time;
+ int state;
+ boolean locked;
+ String callsign;
+ int serial;
+ int flight;
+ int rssi;
+
+ SavedState(AltosState state) {
+ received_time = state.received_time;
+ this.state = state.state();
+ if (state.gps != null)
+ locked = state.gps.locked;
+ else
+ locked = false;
+ callsign = state.cal_data().callsign;
+ serial = state.cal_data().serial;
+ flight = state.cal_data().flight;
+ rssi = state.rssi;
+ }
+}
+
+class Tracker implements CharSequence, Comparable {
+ int serial;
+ String call;
+ double frequency;
+
+ String display;
+
+ public Tracker(int serial, String call, double frequency) {
+ if (call == null)
+ call = "none";
+
+ this.serial = serial;
+ this.call = call;
+ this.frequency = frequency;
+ if (frequency == 0.0)
+ display = "Auto";
+ else if (frequency == AltosLib.MISSING) {
+ display = String.format("%-8.8s %6d", call, serial);
+ } else {
+ display = String.format("%-8.8s %7.3f %6d", call, frequency, serial);
+ }
+ }
+
+ public Tracker(AltosState s) {
+ this(s == null ? 0 : s.cal_data().serial,
+ s == null ? null : s.cal_data().callsign,
+ s == null ? 0.0 : s.frequency);
+ }
+
+ /* CharSequence */
+ public char charAt(int index) {
+ return display.charAt(index);
+ }
+
+ public int length() {
+ return display.length();
+ }
+
+ public CharSequence subSequence(int start, int end) throws IndexOutOfBoundsException {
+ return display.subSequence(start, end);
+ }
+
+ public String toString() {
+ return display.toString();
+ }
+
+ /* Comparable */
+ public int compareTo (Object other) {
+ Tracker o = (Tracker) other;
+ if (frequency == 0.0) {
+ if (o.frequency == 0.0)
+ return 0;
+ return -1;
+ }
+ if (o.frequency == 0.0)
+ return 1;
+
+ int a = serial - o.serial;
+ int b = call.compareTo(o.call);
+ int c = (int) Math.signum(frequency - o.frequency);
+
+ if (b != 0)
+ return b;
+ if (c != 0)
+ return c;
+ return a;
+ }
+}