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.
23 import org.altusmetrum.altoslib_1.*;
24 import org.altusmetrum.altosuilib_1.*;
26 class AltosGraphIterator implements Iterator<AltosUIDataPoint> {
27 AltosGraphDataSet dataSet;
28 Iterator<AltosRecord> iterator;
32 public boolean hasNext() {
33 return iterator.hasNext();
36 public AltosUIDataPoint next() {
37 state = new AltosState(iterator.next(), state);
39 if (dataSet.callsign == null && state.data.callsign != null)
40 dataSet.callsign = state.data.callsign;
42 if (dataSet.serial == 0 && state.data.serial != 0)
43 dataSet.serial = state.data.serial;
45 if (dataSet.flight == 0 && state.data.flight != 0)
46 dataSet.flight = state.data.flight;
48 return new AltosGraphDataPoint(state);
51 public AltosGraphIterator (Iterator<AltosRecord> iterator, AltosGraphDataSet dataSet) {
52 this.iterator = iterator;
54 this.dataSet = dataSet;
57 public void remove() {
61 class AltosGraphIterable implements Iterable<AltosUIDataPoint> {
62 AltosGraphDataSet dataSet;
64 public Iterator<AltosUIDataPoint> iterator() {
65 return new AltosGraphIterator(dataSet.records.iterator(), dataSet);
68 public AltosGraphIterable(AltosGraphDataSet dataSet) {
69 this.dataSet = dataSet;
73 public class AltosGraphDataSet implements AltosUIDataSet {
77 AltosRecordIterable records;
79 public String name() {
81 return String.format("%s - %d/%d", callsign, serial, flight);
83 return String.format("%d/%d", serial, flight);
86 public Iterable<AltosUIDataPoint> dataPoints() {
87 return new AltosGraphIterable(this);
90 public AltosGraphDataSet (AltosRecordIterable records) {
91 this.records = records;