Class RecentFiles

java.lang.Object
edu.cnu.mdi.io.RecentFiles

public final class RecentFiles extends Object
Persistent, preference-backed most-recently-used file list.
  • Constructor Details

    • RecentFiles

      public RecentFiles(Preferences preferences, int maximumSize)
      Create a list using the default preference key prefix.
      Parameters:
      preferences - the preference node backing this list; must not be null
      maximumSize - maximum number of entries retained; must be >= 1
      Throws:
      NullPointerException - if preferences is null
      IllegalArgumentException - if maximumSize < 1
    • RecentFiles

      public 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.
      Parameters:
      preferences - the preference node backing this list; must not be null
      maximumSize - maximum number of entries retained; must be >= 1
      keyPrefix - preference key prefix distinguishing this list from others sharing the same node; must not be blank
      Throws:
      NullPointerException - if preferences is null
      IllegalArgumentException - if maximumSize < 1 or keyPrefix is blank
  • Method Details

    • getMaximumSize

      public int getMaximumSize()
      Returns:
      the maximum number of entries this list retains
    • add

      public void add(File file)
      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 to File.getAbsoluteFile() on IOException) before being compared/stored, so equivalent paths (e.g. differing only by . or symlink segments) are recognized as the same entry. A null file, or one that is not an existing regular file, is silently ignored.

      Parameters:
      file - the file to add; may be null
    • remove

      public void remove(File file)
      Remove a file from the list, if present. Uses the same canonicalization as add(File) for comparison. A no-op if file is null or not currently in the list.
      Parameters:
      file - the file to remove; may be null
    • clear

      public void clear()
      Remove all entries from the list.
    • getRecentFiles

      public List<File> getRecentFiles()
      Return existing regular files in MRU order, pruning stale entries.
    • getRecentPaths

      public List<String> getRecentPaths()
      Returns:
      the same entries as getRecentFiles(), as absolute path strings, in the same MRU order