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_3.*;
24 import org.altusmetrum.altosuilib_1.*;
26 class AltosGraphIterator implements Iterator<AltosUIDataPoint> {
27 AltosGraphDataSet dataSet;
28 Iterator<AltosState> iterator;
30 public boolean hasNext() {
31 return iterator.hasNext();
34 public AltosUIDataPoint next() {
35 AltosState state = iterator.next();
37 if (state.flight != AltosLib.MISSING) {
38 if (dataSet.callsign == null && state.callsign != null)
39 dataSet.callsign = state.callsign;
41 if (dataSet.serial == 0 && state.serial != 0)
42 dataSet.serial = state.serial;
44 if (dataSet.flight == 0 && state.flight != 0)
45 dataSet.flight = state.flight;
48 return new AltosGraphDataPoint(state);
51 public AltosGraphIterator (Iterator<AltosState> iterator, AltosGraphDataSet dataSet) {
52 this.iterator = iterator;
53 this.dataSet = dataSet;
56 public void remove() {
60 class AltosGraphIterable implements Iterable<AltosUIDataPoint> {
61 AltosGraphDataSet dataSet;
63 public Iterator<AltosUIDataPoint> iterator() {
64 return new AltosGraphIterator(dataSet.states.iterator(), dataSet);
67 public AltosGraphIterable(AltosGraphDataSet dataSet) {
68 this.dataSet = dataSet;
72 public class AltosGraphDataSet implements AltosUIDataSet {
76 AltosStateIterable states;
78 public String name() {
80 return String.format("%s - %d/%d", callsign, serial, flight);
82 return String.format("%d/%d", serial, flight);
85 public Iterable<AltosUIDataPoint> dataPoints() {
86 return new AltosGraphIterable(this);
89 public AltosGraphDataSet (AltosStateIterable states) {