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.altosuilib_8;
23 import org.altusmetrum.altoslib_8.*;
25 class AltosGraphIterator implements Iterator<AltosUIDataPoint> {
26 AltosGraphDataSet dataSet;
27 Iterator<AltosState> iterator;
29 public boolean hasNext() {
30 return iterator.hasNext();
33 public AltosUIDataPoint next() {
34 AltosState state = iterator.next();
36 if (state.flight != AltosLib.MISSING) {
37 if (dataSet.callsign == null && state.callsign != null)
38 dataSet.callsign = state.callsign;
40 if (dataSet.serial == 0 && state.serial != 0)
41 dataSet.serial = state.serial;
43 if (dataSet.flight == 0 && state.flight != 0)
44 dataSet.flight = state.flight;
47 return new AltosGraphDataPoint(state);
50 public AltosGraphIterator (Iterator<AltosState> iterator, AltosGraphDataSet dataSet) {
51 this.iterator = iterator;
52 this.dataSet = dataSet;
55 public void remove() {
59 class AltosGraphIterable implements Iterable<AltosUIDataPoint> {
60 AltosGraphDataSet dataSet;
62 public Iterator<AltosUIDataPoint> iterator() {
63 return new AltosGraphIterator(dataSet.states.iterator(), dataSet);
66 public AltosGraphIterable(AltosGraphDataSet dataSet) {
67 this.dataSet = dataSet;
71 public class AltosGraphDataSet implements AltosUIDataSet {
75 AltosStateIterable states;
77 public String name() {
79 return String.format("%s - %d/%d", callsign, serial, flight);
81 return String.format("%d/%d", serial, flight);
84 public Iterable<AltosUIDataPoint> dataPoints() {
85 return new AltosGraphIterable(this);
88 public AltosGraphDataSet (AltosStateIterable states) {