Package edu.cnu.mdi.io
Class RecentFiles
java.lang.Object
edu.cnu.mdi.io.RecentFiles
Persistent, preference-backed most-recently-used file list.
-
Constructor Summary
ConstructorsConstructorDescriptionRecentFiles(Preferences preferences, int maximumSize) Create a list using the default preference key prefix.RecentFiles(Preferences preferences, int maximumSize, String keyPrefix) Create a list with an explicit key prefix, useful when one preference node owns more than one independent recent-file list. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an existing regular file to the front of the list, moving it there if already present.voidclear()Remove all entries from the list.intReturn existing regular files in MRU order, pruning stale entries.voidRemove a file from the list, if present.
-
Constructor Details
-
RecentFiles
Create a list using the default preference key prefix.- Parameters:
preferences- the preference node backing this list; must not benullmaximumSize- maximum number of entries retained; must be >= 1- Throws:
NullPointerException- ifpreferencesisnullIllegalArgumentException- ifmaximumSize < 1
-
RecentFiles
Create a list with an explicit key prefix, useful when one preference node owns more than one independent recent-file list.- Parameters:
preferences- the preference node backing this list; must not benullmaximumSize- maximum number of entries retained; must be >= 1keyPrefix- preference key prefix distinguishing this list from others sharing the same node; must not be blank- Throws:
NullPointerException- ifpreferencesisnullIllegalArgumentException- ifmaximumSize < 1orkeyPrefixis blank
-
-
Method Details
-
getMaximumSize
public int getMaximumSize()- Returns:
- the maximum number of entries this list retains
-
add
Add an existing regular file to the front of the list, moving it there if already present.The file is canonicalized (via
File.getCanonicalFile(), falling back toFile.getAbsoluteFile()onIOException) before being compared/stored, so equivalent paths (e.g. differing only by.or symlink segments) are recognized as the same entry. Anullfile, or one that is not an existing regular file, is silently ignored.- Parameters:
file- the file to add; may benull
-
remove
Remove a file from the list, if present. Uses the same canonicalization asadd(File)for comparison. A no-op iffileisnullor not currently in the list.- Parameters:
file- the file to remove; may benull
-
clear
public void clear()Remove all entries from the list. -
getRecentFiles
Return existing regular files in MRU order, pruning stale entries. -
getRecentPaths
- Returns:
- the same entries as
getRecentFiles(), as absolute path strings, in the same MRU order
-