java: Bump java library versions for next release
[fw/altos] / altosuilib / AltosGraphDataSet.java
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package org.altusmetrum.altosuilib_3;
19
20 import java.lang.*;
21 import java.io.*;
22 import java.util.*;
23 import org.altusmetrum.altoslib_5.*;
24
25 class AltosGraphIterator implements Iterator<AltosUIDataPoint> {
26         AltosGraphDataSet       dataSet;
27         Iterator<AltosState>    iterator;
28
29         public boolean hasNext() {
30                 return iterator.hasNext();
31         }
32
33         public AltosUIDataPoint next() {
34                 AltosState      state = iterator.next();
35
36                 if (state.flight != AltosLib.MISSING) {
37                         if (dataSet.callsign == null && state.callsign != null)
38                                 dataSet.callsign = state.callsign;
39
40                         if (dataSet.serial == 0 && state.serial != 0)
41                                 dataSet.serial = state.serial;
42
43                         if (dataSet.flight == 0 && state.flight != 0)
44                                 dataSet.flight = state.flight;
45                 }
46
47                 return new AltosGraphDataPoint(state);
48         }
49
50         public AltosGraphIterator (Iterator<AltosState> iterator, AltosGraphDataSet dataSet) {
51                 this.iterator = iterator;
52                 this.dataSet = dataSet;
53         }
54
55         public void remove() {
56         }
57 }
58
59 class AltosGraphIterable implements Iterable<AltosUIDataPoint> {
60         AltosGraphDataSet       dataSet;
61
62         public Iterator<AltosUIDataPoint> iterator() {
63                 return new AltosGraphIterator(dataSet.states.iterator(), dataSet);
64         }
65
66         public AltosGraphIterable(AltosGraphDataSet dataSet) {
67                 this.dataSet = dataSet;
68         }
69 }
70
71 public class AltosGraphDataSet implements AltosUIDataSet {
72         String                  callsign;
73         int                     serial;
74         int                     flight;
75         AltosStateIterable      states;
76
77         public String name() {
78                 if (callsign != null)
79                         return String.format("%s - %d/%d", callsign, serial, flight);
80                 else
81                         return String.format("%d/%d", serial, flight);
82         }
83
84         public Iterable<AltosUIDataPoint> dataPoints() {
85                 return new AltosGraphIterable(this);
86         }
87
88         public AltosGraphDataSet (AltosStateIterable states) {
89                 this.states = states;
90                 this.callsign = null;
91                 this.serial = 0;
92                 this.flight = 0;
93         }
94 }