1 package tim.prune.data;
6 * Class to hold the source of the point data, including the original file
7 * and file type, and references to each of the point objects
9 public class SourceInfo
11 /** File type of source file */
12 public enum FILE_TYPE {TEXT, GPX, KML, NMEA, GPSBABEL, GPSIES, JSON};
15 private File _sourceFile = null;
17 private String _sourceName = null;
19 private FILE_TYPE _fileType = null;
20 /** File title, if any */
21 private String _fileTitle = null;
23 /** Array of datapoints */
24 private DataPoint[] _points = null;
25 /** Number of points */
26 private int _numPoints = 0;
27 /** Array of point indices (if necessary) */
28 private int[] _pointIndices = null;
33 * @param inFile source file
34 * @param inType type of file
36 public SourceInfo(File inFile, FILE_TYPE inType)
39 _sourceName = inFile.getName();
45 * @param inName name of source (without file)
46 * @param inType type of file
48 public SourceInfo(String inName, FILE_TYPE inType)
56 * @param inTitle title of file, eg from <name> tag in gpx
58 public void setFileTitle(String inTitle)
74 public String getName()
80 * @return file type of source
82 public FILE_TYPE getFileType()
88 * @return title of file
90 public String getFileTitle()
96 * @return number of points from this source
98 public int getNumPoints()
104 * Set the indices of the points selected out of a loaded track
105 * @param inSelectedFlags array of booleans showing whether each point in the original data was loaded or not
107 public void setPointIndices(boolean[] inSelectedFlags)
109 _numPoints = inSelectedFlags.length;
110 _pointIndices = new int[_numPoints];
112 for (int i=0; i<_numPoints; i++) {
113 if (inSelectedFlags[i]) {_pointIndices[p++] = i;}
115 // Now the point indices array holds the index of each of the selected points
119 * Take the points from the given track and store
120 * @param inTrack track object containing points
121 * @param inNumPoints number of points loaded
123 public void populatePointObjects(Track inTrack, int inNumPoints)
125 if (_numPoints == 0) {_numPoints = inNumPoints;}
128 _points = new DataPoint[inNumPoints];
129 int trackLen = inTrack.getNumPoints();
130 System.arraycopy(inTrack.cloneContents(), trackLen-inNumPoints, _points, 0, inNumPoints);
131 // Note data copied twice here but still more efficient than looping
136 * Look for the given point in the array
137 * @param inPoint point to look for
138 * @return index, or -1 if not found
140 public int getIndex(DataPoint inPoint)
143 for (int i=0; i<_points.length; i++)
145 if (_points[i] == inPoint) {
150 if (idx == -1) {return idx;} // point not found
151 if (_pointIndices == null) {return idx;} // All points loaded
152 return _pointIndices[idx]; // use point index mapping