public class RecentFileList
extends java.lang.Object
RecentFileList can load and store data to a backing store which maps Strings
to Strings; in normal use in the PuffinPlot desktop application, a
Preferences
object fulfils this role. The constructor
and save method take functional interfaces as arguments, so any object
providing put, get, and remove methods for a String-to-String map can be used
as a store. RecentFileList prefixes its keys with the string
recentFileX
, where X is a non-negative integer less than the maximum
number of file-sets. Note that RecentFileList does not synchronize with the
store, except on instantiation (when it is initialized from the supplied
getter) and on a call to save
(when it writes to the store using
the supplied remover and putter).
Constructor and Description |
---|
RecentFileList(java.util.function.UnaryOperator<java.lang.String> getter)
Creates a new file list, reading data (if any) using the supplied getter.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.util.List<java.io.File> files)
Adds a new file-set to the top of the list.
|
java.util.List<java.io.File> |
getFilesAndReorder(int index)
Returns a specified file-set and moves it to the top of the list.
|
java.util.List<java.lang.String> |
getFilesetLongNames()
Gets a list containing a long name for each fileset, intended for
use in the tooltips of the recent files menu.
|
java.lang.String[] |
getFilesetNames()
Gets a list containing the names of the file-sets in the file list.
|
void |
save(java.util.function.Consumer<java.lang.String> remover,
java.util.function.BiConsumer<java.lang.String,java.lang.String> putter)
Stores the recent file list using the supplied remover and putter
functions.
|
public RecentFileList(java.util.function.UnaryOperator<java.lang.String> getter)
null
for a non-existent key. If any of the
recentFile0
(and so on) keys are absent, no error is raised, and
the corresponding slots in the file list are left empty.getter
- a function which takes a key and returns a value from a
backing storepublic void save(java.util.function.Consumer<java.lang.String> remover, java.util.function.BiConsumer<java.lang.String,java.lang.String> putter)
remover
- a function which takes a key and removes the corresponding
key-value pair from a backing store. If the key is absent, it should
do nothing.putter
- a function which stores a key-value pair, taking a key as
the first argument and a value as the second argument. It will not be
called with a null key or with a null value.public java.lang.String[] getFilesetNames()
public java.util.List<java.lang.String> getFilesetLongNames()
public java.util.List<java.io.File> getFilesAndReorder(int index)
index
- the zero-based index of a file-set within the listpublic void add(java.util.List<java.io.File> files)
files
- the files to be added (as a single file-set) to the list