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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altoslib_5;
24 class AltosEepromOrdered implements Comparable<AltosEepromOrdered> {
30 if (eeprom.cmd == AltosLib.AO_LOG_FLIGHT)
35 public int compareTo(AltosEepromOrdered o) {
36 int cmd_diff = cmdi() - o.cmdi();
41 if (eeprom.has_seconds() && o.eeprom.has_seconds()) {
42 int seconds_diff = eeprom.seconds() - o.eeprom.seconds();
44 if (seconds_diff != 0)
48 int tick_diff = tick - o.tick;
52 return index - o.index;
55 AltosEepromOrdered (AltosEeprom eeprom, int index, int tick) {
62 class AltosEepromOrderedIterator implements Iterator<AltosEeprom> {
63 TreeSet<AltosEepromOrdered> olist;
64 Iterator<AltosEepromOrdered> oiterator;
66 public AltosEepromOrderedIterator(Iterable<AltosEeprom> eeproms) {
67 olist = new TreeSet<AltosEepromOrdered>();
73 for (AltosEeprom e : eeproms) {
78 while (t < tick - 32767)
82 olist.add(new AltosEepromOrdered(e, index++, tick));
86 oiterator = olist.iterator();
89 public boolean hasNext() {
90 return oiterator.hasNext();
93 public AltosEeprom next() {
94 return oiterator.next().eeprom;
97 public void remove () {
101 public class AltosEepromIterable implements Iterable<AltosEeprom> {
102 public LinkedList<AltosEeprom> eeproms;
104 public void write(PrintStream out) {
105 for (AltosEeprom eeprom : eeproms)
109 public AltosState state() {
110 AltosState state = new AltosState();
112 for (AltosEeprom header : eeproms)
113 header.update_state(state);
117 public AltosEepromIterable(LinkedList<AltosEeprom> eeproms) {
118 this.eeproms = eeproms;
121 public Iterator<AltosEeprom> iterator() {
123 eeproms = new LinkedList<AltosEeprom>();
124 return new AltosEepromOrderedIterator(eeproms);