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