]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/RecentFile.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / data / RecentFile.java
1 package tim.prune.data;
2
3 import java.io.File;
4
5 /**
6  * Simple class to represent an entry in the recently-used files list
7  */
8 public class RecentFile
9 {
10         private boolean _regularLoad = true; // false for load via gpsbabel
11         private File _file = null;
12
13         /**
14          * Constructor
15          * @param inFile file
16          * @param inRegular true for regular load, false for gpsbabel load
17          */
18         public RecentFile(File inFile, boolean inRegular)
19         {
20                 _file = inFile;
21                 _regularLoad = inRegular;
22         }
23
24         /**
25          * Constructor
26          * @param inDesc String from config
27          */
28         public RecentFile(String inDesc)
29         {
30                 if (inDesc != null && inDesc.length() > 3)
31                 {
32                         _regularLoad = (inDesc.charAt(0) != 'g');
33                         _file = new File(inDesc.substring(1));
34                 }
35         }
36
37         /**
38          * @return file object
39          */
40         public File getFile() {
41                 return _file;
42         }
43
44         /**
45          * @return true for regular load, false for gpsbabel load
46          */
47         public boolean isRegularLoad() {
48                 return _regularLoad;
49         }
50
51         /**
52          * @return true if file (still) exists
53          */
54         public boolean isValid() {
55                 return _file != null && _file.exists() && _file.isFile();
56         }
57
58         /**
59          * @return string to save in config
60          */
61         public String getConfigString()
62         {
63                 if (!isValid()) return "";
64                 return (_regularLoad?"r":"g") + _file.getAbsolutePath();
65         }
66
67         /**
68          * Check for equality
69          * @param inOther other RecentFile object
70          * @return true if they both refer to the same file
71          */
72         public boolean isSameFile(RecentFile inOther)
73         {
74                 return inOther != null && isValid() && inOther.isValid()
75                         && (_file.equals(inOther._file) || _file.getAbsolutePath().equals(inOther._file.getAbsolutePath()));
76                 // Note that the file.equals should be sufficient but sometimes it returns false even if the absolute paths are identical
77         }
78 }