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};
15 private File _sourceFile = null;
17 private String _sourceName = null;
19 private FILE_TYPE _fileType = null;
21 /** Array of datapoints */
22 private DataPoint[] _points = null;
23 /** Number of points */
24 private int _numPoints = 0;
25 /** Array of point indices (if necessary) */
26 private int[] _pointIndices = null;
31 * @param inFile source file
32 * @param inType type of file
34 public SourceInfo(File inFile, FILE_TYPE inType)
37 _sourceName = inFile.getName();
43 * @param inName name of source (without file)
44 * @param inType type of file
46 public SourceInfo(String inName, FILE_TYPE inType)
64 public String getName()
70 * @return file type of source
72 public FILE_TYPE getFileType()
78 * @return number of points from this source
80 public int getNumPoints()
86 * Set the indices of the points selected out of a loaded track
87 * @param inSelectedFlags array of booleans showing whether each point in the original data was loaded or not
89 public void setPointIndices(boolean[] inSelectedFlags)
91 _numPoints = inSelectedFlags.length;
92 _pointIndices = new int[_numPoints];
94 for (int i=0; i<_numPoints; i++) {
95 if (inSelectedFlags[i]) {_pointIndices[p++] = i;}
97 // Now the point indices array holds the index of each of the selected points
101 * Take the points from the given track and store
102 * @param inTrack track object containing points
103 * @param inNumPoints number of points loaded
105 public void populatePointObjects(Track inTrack, int inNumPoints)
107 if (_numPoints == 0) {_numPoints = inNumPoints;}
110 _points = new DataPoint[inNumPoints];
111 int trackLen = inTrack.getNumPoints();
112 System.arraycopy(inTrack.cloneContents(), trackLen-inNumPoints, _points, 0, inNumPoints);
113 // Note data copied twice here but still more efficient than looping
118 * Look for the given point in the array
119 * @param inPoint point to look for
120 * @return index, or -1 if not found
122 public int getIndex(DataPoint inPoint)
125 for (int i=0; i<_points.length && (idx < 0); i++) {
126 if (_points[i] == inPoint) {idx = i;}
128 if (_pointIndices == null) {return idx;} // All points loaded
129 return _pointIndices[idx]; // use point index mapping