Top Description Fields Constructors Methods
org.apache.pdfbox.debugger.ui

public Class RecentFiles

extends Object
Class Inheritance
Imports
java.io.File, .IOException, java.util.ArrayDeque, .ArrayList, .List, .Queue, java.util.prefs.Preferences, java.util.stream.Collectors

A class to save recent file history in preference using java Preference api.

Field Summary

Modifier and TypeField and Description
private Queue<String>
private static final String
private static final String
private final int
private static final String
private static final String
private final Preferences

Constructor Summary

AccessConstructor and Description
public
RecentFiles(Class<?>
the class for which this Recentfiles object is created and it will be used to create preference instance.
className
,
int
the number of recent files to remember.
maximumFile
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
addFile(String
path to the file. this path means File#getPath() method returned String.
path
)

Add a new file in recent file history.

private String[]
breakString(String fullPath)

public void
close()

This method save the present recent file history in the preference.

public List<String>

Returns:

return the file paths in a List.
getFiles
()

This gives the file in descending order where order is according to the time it is added.

public boolean

Returns:

if history is empty return true otherwise return false.
isEmpty
()

Check if file history is empty.

private Queue<String>
public void
removeAll()

Clear the previous recent file history.

public void
removeFile(String
path string to the file. this path means File#getPath() method returned String.
path
)

Remove a file from recent file history.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

filePathsback to summary
private Queue<String> filePaths
HISTORY_LENGTHback to summary
private static final String HISTORY_LENGTH
KEYback to summary
private static final String KEY
maximumback to summary
private final int maximum
PATH_KEYback to summary
private static final String PATH_KEY
PIECES_LENGTH_KEYback to summary
private static final String PIECES_LENGTH_KEY
prefback to summary
private final Preferences pref

Constructor Detail

RecentFilesback to summary
public RecentFiles(Class<?> className, int maximumFile)

Constructor.

Parameters
className:Class<?>

the class for which this Recentfiles object is created and it will be used to create preference instance.

maximumFile:int

the number of recent files to remember.

Method Detail

addFileback to summary
public void addFile(String path)

Add a new file in recent file history.

Parameters
path:String

path to the file. this path means File#getPath() method returned String.

breakStringback to summary
private String[] breakString(String fullPath)
closeback to summary
public void close() throws IOException

This method save the present recent file history in the preference. To get the recent file history in next session this method must be called.

Exceptions
IOException:
if saving in preference doesn't success.
getFilesback to summary
public List<String> getFiles()

This gives the file in descending order where order is according to the time it is added. This checks for file's existence in file history.

Returns:List<String>

return the file paths in a List.

isEmptyback to summary
public boolean isEmpty()

Check if file history is empty.

Returns:boolean

if history is empty return true otherwise return false.

readHistoryFromPrefback to summary
private Queue<String> readHistoryFromPref()
removeAllback to summary
public void removeAll()

Clear the previous recent file history.

removeFileback to summary
public void removeFile(String path)

Remove a file from recent file history.

Parameters
path:String

path string to the file. this path means File#getPath() method returned String.

writeHistoryToPrefback to summary
private void writeHistoryToPref(Queue<String> filePaths)