File: RecentFile.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (78 lines) | stat: -rw-r--r-- 1,711 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package tim.prune.data;

import java.io.File;

/**
 * Simple class to represent an entry in the recently-used files list
 */
public class RecentFile
{
	private boolean _regularLoad = true; // false for load via gpsbabel
	private File _file = null;

	/**
	 * Constructor
	 * @param inFile file
	 * @param inRegular true for regular load, false for gpsbabel load
	 */
	public RecentFile(File inFile, boolean inRegular)
	{
		_file = inFile;
		_regularLoad = inRegular;
	}

	/**
	 * Constructor
	 * @param inDesc String from config
	 */
	public RecentFile(String inDesc)
	{
		if (inDesc != null && inDesc.length() > 3)
		{
			_regularLoad = (inDesc.charAt(0) != 'g');
			_file = new File(inDesc.substring(1));
		}
	}

	/**
	 * @return file object
	 */
	public File getFile() {
		return _file;
	}

	/**
	 * @return true for regular load, false for gpsbabel load
	 */
	public boolean isRegularLoad() {
		return _regularLoad;
	}

	/**
	 * @return true if file (still) exists
	 */
	public boolean isValid() {
		return _file != null && _file.exists() && _file.isFile();
	}

	/**
	 * @return string to save in config
	 */
	public String getConfigString()
	{
		if (!isValid()) return "";
		return (_regularLoad?"r":"g") + _file.getAbsolutePath();
	}

	/**
	 * Check for equality
	 * @param inOther other RecentFile object
	 * @return true if they both refer to the same file
	 */
	public boolean isSameFile(RecentFile inOther)
	{
		return inOther != null && isValid() && inOther.isValid()
			&& (_file.equals(inOther._file) || _file.getAbsolutePath().equals(inOther._file.getAbsolutePath()));
		// Note that the file.equals should be sufficient but sometimes it returns false even if the absolute paths are identical
	}
}