]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/profile/ProfileData.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / gui / profile / ProfileData.java
1 package tim.prune.gui.profile;
2
3 import tim.prune.data.Track;
4 import tim.prune.data.UnitSet;
5
6 /**
7  * Abstract class for all sources of profile data,
8  * including altitudes and speeds
9  */
10 public abstract class ProfileData
11 {
12         /** Track object */
13         protected final Track _track;
14         /** Unit set to use */
15         protected UnitSet _unitSet = null;
16         /** Flag for availability of any data */
17         protected boolean _hasData = false;
18         /** Array of booleans for data per point */
19         protected boolean[] _pointHasData = null;
20         /** Array of values per point */
21         protected double[] _pointValues = null;
22         /** Minimum value for track */
23         protected double _minValue = 0.0;
24         /** Maximum value for track */
25         protected double _maxValue = 0.0;
26
27         /**
28          * Constructor giving track object
29          * @param inTrack track object
30          */
31         public ProfileData(Track inTrack)
32         {
33                 _track = inTrack;
34         }
35
36         /**
37          * @return true if this source has any data at all
38          */
39         public boolean hasData() {
40                 return _hasData;
41         }
42
43         /**
44          * @param inPointNum index of point
45          * @return true if that point has data
46          */
47         public boolean hasData(int inPointNum)
48         {
49                 return (_hasData && _pointHasData != null && inPointNum >= 0
50                         && inPointNum < _pointHasData.length && _pointHasData[inPointNum]);
51         }
52
53         /**
54          * @param inPointNum index of point
55          * @return value corresponding to that point
56          */
57         public double getData(int inPointNum)
58         {
59                 if (!hasData(inPointNum)) {return 0.0;}
60                 return _pointValues[inPointNum];
61         }
62
63         /**
64          * @return minimum value
65          */
66         public double getMinValue() {
67                 return _minValue;
68         }
69
70         /**
71          * @return maximum value
72          */
73         public double getMaxValue() {
74                 return _maxValue;
75         }
76
77         /**
78          * Get the data from the track and populate the value arrays
79          */
80         public abstract void init(UnitSet inUnitSet);
81
82         /**
83          * Set the UnitSet to use for the calculations
84          * @param inUnitSet unit set
85          */
86         protected void setUnitSet(UnitSet inUnitSet) {
87                 _unitSet = inUnitSet;
88         }
89
90         /**
91          * @return text for label including units
92          */
93         public abstract String getLabel();
94
95         /**
96          * @return key for message when no data available
97          */
98         public abstract String getNoDataKey();
99
100         /**
101          * Initialise the data arrays to the correct size
102          */
103         protected void initArrays()
104         {
105                 int numTrackPoints = _track.getNumPoints();
106                 if (_pointHasData == null || _pointHasData.length != numTrackPoints)
107                 {
108                         _pointHasData = new boolean[numTrackPoints];
109                         _pointValues = new double[numTrackPoints];
110                 }
111         }
112 }