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_4;
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 int tick_diff = tick - o.tick;
45 return index - o.index;
48 AltosEepromOrdered (AltosEeprom eeprom, int index, int tick) {
55 class AltosEepromOrderedIterator implements Iterator<AltosEeprom> {
56 TreeSet<AltosEepromOrdered> olist;
57 Iterator<AltosEepromOrdered> oiterator;
59 public AltosEepromOrderedIterator(Iterable<AltosEeprom> eeproms) {
60 olist = new TreeSet<AltosEepromOrdered>();
66 for (AltosEeprom e : eeproms) {
71 while (t < tick - 32767)
75 olist.add(new AltosEepromOrdered(e, index++, tick));
79 oiterator = olist.iterator();
82 public boolean hasNext() {
83 return oiterator.hasNext();
86 public AltosEeprom next() {
87 return oiterator.next().eeprom;
90 public void remove () {
94 public class AltosEepromIterable implements Iterable<AltosEeprom> {
95 public LinkedList<AltosEeprom> eeproms;
97 public void write(PrintStream out) {
98 for (AltosEeprom eeprom : eeproms)
102 public AltosState state() {
103 AltosState state = new AltosState();
105 for (AltosEeprom header : eeproms)
106 header.update_state(state);
110 public AltosEepromIterable(LinkedList<AltosEeprom> eeproms) {
111 this.eeproms = eeproms;
114 public Iterator<AltosEeprom> iterator() {
116 eeproms = new LinkedList<AltosEeprom>();
117 return new AltosEepromOrderedIterator(eeproms);