1 package tim.prune.gui.profile;
3 import tim.prune.data.Track;
4 import tim.prune.data.UnitSet;
7 * Abstract class for all sources of profile data,
8 * including altitudes and speeds
10 public abstract class ProfileData
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;
28 * Constructor giving track object
29 * @param inTrack track object
31 public ProfileData(Track inTrack)
37 * @return true if this source has any data at all
39 public boolean hasData() {
44 * @param inPointNum index of point
45 * @return true if that point has data
47 public boolean hasData(int inPointNum)
49 return (_hasData && _pointHasData != null && inPointNum >= 0
50 && inPointNum < _pointHasData.length && _pointHasData[inPointNum]);
54 * @param inPointNum index of point
55 * @return value corresponding to that point
57 public double getData(int inPointNum)
59 if (!hasData(inPointNum)) {return 0.0;}
60 return _pointValues[inPointNum];
64 * @return minimum value
66 public double getMinValue() {
71 * @return maximum value
73 public double getMaxValue() {
78 * Get the data from the track and populate the value arrays
80 public abstract void init(UnitSet inUnitSet);
83 * Set the UnitSet to use for the calculations
84 * @param inUnitSet unit set
86 protected void setUnitSet(UnitSet inUnitSet) {
91 * @return text for label including units
93 public abstract String getLabel();
96 * @return key for message when no data available
98 public abstract String getNoDataKey();
101 * Initialise the data arrays to the correct size
103 protected void initArrays()
105 int numTrackPoints = _track.getNumPoints();
106 if (_pointHasData == null || _pointHasData.length != numTrackPoints)
108 _pointHasData = new boolean[numTrackPoints];
109 _pointValues = new double[numTrackPoints];