2 * Copyright © 2013 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altoslib_11;
25 class AltosEepromOrdered implements Comparable<AltosEepromOrdered> {
31 if (eeprom.cmd == AltosLib.AO_LOG_FLIGHT)
36 public int compareTo(AltosEepromOrdered o) {
37 int cmd_diff = cmdi() - o.cmdi();
42 if (eeprom.has_seconds() && o.eeprom.has_seconds()) {
43 int seconds_diff = eeprom.seconds() - o.eeprom.seconds();
45 if (seconds_diff != 0)
49 int tick_diff = tick - o.tick;
53 return index - o.index;
56 AltosEepromOrdered (AltosEeprom eeprom, int index, int tick) {
63 class AltosEepromOrderedIterator implements Iterator<AltosEeprom> {
64 TreeSet<AltosEepromOrdered> olist;
65 Iterator<AltosEepromOrdered> oiterator;
67 public AltosEepromOrderedIterator(Iterable<AltosEeprom> eeproms) {
68 olist = new TreeSet<AltosEepromOrdered>();
74 for (AltosEeprom e : eeproms) {
79 while (t < tick - 32767)
83 olist.add(new AltosEepromOrdered(e, index++, tick));
87 oiterator = olist.iterator();
90 public boolean hasNext() {
91 return oiterator.hasNext();
94 public AltosEeprom next() {
95 return oiterator.next().eeprom;
98 public void remove () {
102 public class AltosEepromIterable implements Iterable<AltosEeprom> {
103 public LinkedList<AltosEeprom> eeproms;
105 public void write(PrintStream out) {
106 for (AltosEeprom eeprom : eeproms)
110 public AltosState state() {
111 AltosState state = new AltosState();
113 for (AltosEeprom header : eeproms)
114 header.update_state(state);
118 public AltosEepromIterable(LinkedList<AltosEeprom> eeproms) {
119 this.eeproms = eeproms;
122 public Iterator<AltosEeprom> iterator() {
124 eeproms = new LinkedList<AltosEeprom>();
125 return new AltosEepromOrderedIterator(eeproms);