]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/FileInfo.java
1fd56b94b76aca28739c809bb11f3f78d48ce77f
[GpsPrune.git] / tim / prune / data / FileInfo.java
1 package tim.prune.data;
2
3 import java.util.ArrayList;
4
5 /**
6  * Class to hold the information about the file(s)
7  * from which the data was loaded from / saved to
8  */
9 public class FileInfo
10 {
11         /** List of sources */
12         private ArrayList<SourceInfo> _sources = new ArrayList<SourceInfo>();
13
14
15         /**
16          * Empty constructor
17          */
18         public FileInfo()
19         {}
20
21         /**
22          * Private constructor for creating clone
23          * @param inList list of sources
24          */
25         private FileInfo(ArrayList<SourceInfo> inList)
26         {
27                 _sources = inList;
28         }
29
30         /**
31          * Add a data source to the list
32          * @param inInfo info object to add
33          */
34         public void addSource(SourceInfo inInfo)
35         {
36                 _sources.add(inInfo);
37         }
38
39         /**
40          * Replace the list of data sources with the given source
41          * @param inInfo new source
42          */
43         public void replaceSource(SourceInfo inInfo)
44         {
45                 _sources.clear();
46                 addSource(inInfo);
47         }
48
49         /**
50          * remove the last source added
51          */
52         public void removeSource()
53         {
54                 _sources.remove(_sources.size()-1);
55         }
56
57         /**
58          * @return the number of files loaded
59          */
60         public int getNumFiles()
61         {
62                 return _sources.size();
63         }
64
65
66         /**
67          * @return The source name, if a single file
68          */
69         public String getFilename()
70         {
71                 if (getNumFiles() == 1)
72                         return _sources.get(0).getName();
73                 return "";
74         }
75
76         /**
77          * @param inIndex index number
78          * @return source info object
79          */
80         public SourceInfo getSource(int inIndex) {
81                 return _sources.get(inIndex);
82         }
83
84         /**
85          * Clone contents of file info
86          */
87         @SuppressWarnings("unchecked")
88         public FileInfo clone()
89         {
90                 // copy source list
91                 ArrayList<SourceInfo> copy = (ArrayList<SourceInfo>) _sources.clone();
92                 return new FileInfo(copy);
93         }
94 }