1 package tim.prune.gui.profile;
3 import tim.prune.data.Track;
6 * Abstract class for all sources of profile data,
7 * including altitudes and speeds
9 public abstract class ProfileData
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;
25 * Constructor giving track object
26 * @param inTrack track object
28 public ProfileData(Track inTrack)
34 * @return true if this source has any data at all
36 public boolean hasData() {
41 * @param inPointNum index of point
42 * @return true if that point has data
44 public boolean hasData(int inPointNum)
46 return (_hasData && _pointHasData != null && inPointNum >= 0
47 && inPointNum < _pointHasData.length && _pointHasData[inPointNum]);
51 * @param inPointNum index of point
52 * @return value corresponding to that point
54 public double getData(int inPointNum)
56 if (!hasData(inPointNum)) {return 0.0;}
57 return _pointValues[inPointNum];
61 * @return minimum value
63 public double getMinValue() {
68 * @return maximum value
70 public double getMaxValue() {
75 * Get the data from the track and populate the value arrays
77 public abstract void init();
80 * @return text for label including units
82 public abstract String getLabel();
85 * @return key for message when no data available
87 public abstract String getNoDataKey();
90 * Initialise the data arrays
92 protected void initArrays()
94 int numTrackPoints = _track.getNumPoints();
95 if (_pointHasData == null || _pointHasData.length != numTrackPoints)
97 _pointHasData = new boolean[numTrackPoints];
98 _pointValues = new double[numTrackPoints];