public class RecentFileList extends 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(UnaryOperator<String> getter)
Creates a new file list, reading data (if any) using the supplied getter.
|
Modifier and Type | Method and Description |
---|---|
void |
add(List<File> files)
Adds a new file-set to the top of the list.
|
List<File> |
getFilesAndReorder(int index)
Returns a specified file-set and moves it to the top of the list.
|
List<String> |
getFilesetLongNames()
Gets a list containing a long name for each fileset, intended for
use in the tooltips of the recent files menu.
|
String[] |
getFilesetNames()
Gets a list containing the names of the file-sets in the file list.
|
void |
save(Consumer<String> remover,
BiConsumer<String,String> putter)
Stores the recent file list using the supplied remover and putter
functions.
|
public RecentFileList(UnaryOperator<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(Consumer<String> remover, BiConsumer<String,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 String[] getFilesetNames()
public List<String> getFilesetLongNames()
public List<File> getFilesAndReorder(int index)
index
- the zero-based index of a file-set within the listCopyright © 2022. All rights reserved.