]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/SourceInfo.java
bbe8baa3d9cfb269eb9efcbd268b4a48976a2d8f
[GpsPrune.git] / tim / prune / data / SourceInfo.java
1 package tim.prune.data;
2
3 import java.io.File;
4
5 /**
6  * Class to hold the source of the point data,
7  * including original file and file type, and
8  * also file offsets for source copying
9  */
10 public class SourceInfo
11 {
12         /** File type of source file */
13         public enum FILE_TYPE {TEXT, GPX, KML, NMEA, GPSBABEL, GPSIES};
14
15         /** Source file */
16         private File _sourceFile = null;
17         /** Name of source */
18         private String _sourceName = null;
19         /** File type */
20         private FILE_TYPE _fileType = null;
21
22         /** Array of datapoints */
23         private DataPoint[] _points = null;
24
25
26         /**
27          * Constructor
28          * @param inFile source file
29          * @param inType type of file
30          */
31         public SourceInfo(File inFile, FILE_TYPE inType)
32         {
33                 _sourceFile = inFile;
34                 _sourceName = inFile.getName();
35                 _fileType = inType;
36         }
37
38         /**
39          * Constructor
40          * @param inName name of source (without file)
41          * @param inType type of file
42          */
43         public SourceInfo(String inName, FILE_TYPE inType)
44         {
45                 _sourceFile = null;
46                 _sourceName = inName;
47                 _fileType = inType;
48         }
49
50         /**
51          * @return source file
52          */
53         public File getFile()
54         {
55                 return _sourceFile;
56         }
57
58         /**
59          * @return source name
60          */
61         public String getName()
62         {
63                 return _sourceName;
64         }
65
66         /**
67          * @return file type of source
68          */
69         public FILE_TYPE getFileType()
70         {
71                 return _fileType;
72         }
73
74         /**
75          * @return number of points from this source
76          */
77         public int getNumPoints()
78         {
79                 return _points.length;
80         }
81
82         /**
83          * Take the points from the given track and store
84          * @param inTrack track object containing points
85          * @param inNumPoints number of points loaded
86          */
87         public void populatePointObjects(Track inTrack, int inNumPoints)
88         {
89                 if (inNumPoints > 0)
90                 {
91                         _points = new DataPoint[inNumPoints];
92                         int trackLen = inTrack.getNumPoints();
93                         System.arraycopy(inTrack.cloneContents(), trackLen-inNumPoints, _points, 0, inNumPoints);
94                         // Note data copied twice here but still more efficient than looping
95                 }
96         }
97
98         /**
99          * Look for the given point in the array
100          * @param inPoint point to look for
101          * @return index, or -1 if not found
102          */
103         public int getIndex(DataPoint inPoint)
104         {
105                 int idx = -1;
106                 for (int i=0; i<_points.length && (idx < 0); i++) {
107                         if (_points[i] == inPoint) {idx = i;}
108                 }
109                 return idx;
110         }
111 }