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 ((state.data.seen & AltosRecord.seen_flight) != 0) {
40 if (dataSet.callsign == null && state.data.callsign != null)
41 dataSet.callsign = state.data.callsign;
43 if (dataSet.serial == 0 && state.data.serial != 0)
44 dataSet.serial = state.data.serial;
46 if (dataSet.flight == 0 && state.data.flight != 0)
47 dataSet.flight = state.data.flight;
50 return new AltosGraphDataPoint(state);
53 public AltosGraphIterator (Iterator<AltosRecord> iterator, AltosGraphDataSet dataSet) {
54 this.iterator = iterator;
56 this.dataSet = dataSet;
59 public void remove() {
63 class AltosGraphIterable implements Iterable<AltosUIDataPoint> {
64 AltosGraphDataSet dataSet;
66 public Iterator<AltosUIDataPoint> iterator() {
67 return new AltosGraphIterator(dataSet.records.iterator(), dataSet);
70 public AltosGraphIterable(AltosGraphDataSet dataSet) {
71 this.dataSet = dataSet;
75 public class AltosGraphDataSet implements AltosUIDataSet {
79 AltosRecordIterable records;
81 public String name() {
83 return String.format("%s - %d/%d", callsign, serial, flight);
85 return String.format("%d/%d", serial, flight);
88 public Iterable<AltosUIDataPoint> dataPoints() {
89 return new AltosGraphIterable(this);
92 public AltosGraphDataSet (AltosRecordIterable records) {
93 this.records = records;