public class DefaultHistory extends Object implements History
History
using a file for persistent backing.
Implementers should install shutdown hook to call DefaultHistory.save()
to save history to disk.
Modifier and Type | Class and Description |
---|---|
protected static class |
DefaultHistory.EntryImpl |
History.Entry
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_HISTORY_FILE_SIZE |
static int |
DEFAULT_HISTORY_SIZE |
Constructor and Description |
---|
DefaultHistory() |
DefaultHistory(LineReader reader) |
Modifier and Type | Method and Description |
---|---|
void |
add(Instant time,
String line) |
protected void |
addHistoryLine(Path path,
String line) |
protected void |
addHistoryLine(Path path,
String line,
boolean checkDuplicates) |
void |
append(Path file,
boolean incremental)
Append history to the file.
|
void |
attach(LineReader reader)
Initialize the history for the given reader.
|
protected DefaultHistory.EntryImpl |
createEntry(int index,
Instant time,
String line)
Create a history entry.
|
String |
current()
Return the content of the current buffer.
|
int |
first() |
String |
get(int index) |
int |
index() |
protected void |
internalAdd(Instant time,
String line) |
protected void |
internalAdd(Instant time,
String line,
boolean checkDuplicates) |
boolean |
isEmpty() |
ListIterator<History.Entry> |
iterator(int index) |
int |
last() |
void |
load()
Load history.
|
protected boolean |
matchPatterns(String patterns,
String line) |
boolean |
moveTo(int index)
Move to the specified index in the history
|
void |
moveToEnd()
Move to the end of the history buffer.
|
boolean |
moveToFirst()
Moves the history index to the first entry.
|
boolean |
moveToLast()
This moves the history to the last entry.
|
boolean |
next()
Move the pointer to the next element in the buffer.
|
boolean |
previous()
Move the pointer to the previous element in the buffer.
|
void |
purge()
Purge history.
|
void |
read(Path file,
boolean checkDuplicates)
Read history from the file.
|
void |
resetIndex()
Reset index after remove
|
void |
save()
Save history.
|
int |
size() |
Spliterator<History.Entry> |
spliterator() |
String |
toString() |
protected void |
trimHistory(Path path,
int max) |
void |
write(Path file,
boolean incremental)
Write history to the file.
|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
add, isPersistable, iterator, reverseIterator, reverseIterator
public static final int DEFAULT_HISTORY_SIZE
public static final int DEFAULT_HISTORY_FILE_SIZE
public DefaultHistory()
public DefaultHistory(LineReader reader)
public void attach(LineReader reader)
History
public void load() throws IOException
History
load
in interface History
IOException
- if a problem occurspublic void read(Path file, boolean checkDuplicates) throws IOException
History
true
only the events that
are not contained within the internal list are added.read
in interface History
file
- History filecheckDuplicates
- If true
, duplicate history entries will be discardedIOException
- if a problem occurspublic void purge() throws IOException
History
purge
in interface History
IOException
- if a problem occurspublic void write(Path file, boolean incremental) throws IOException
History
write
in interface History
file
- History fileincremental
- If true incremental write operation is performed.IOException
- if a problem occurspublic void append(Path file, boolean incremental) throws IOException
History
append
in interface History
file
- History fileincremental
- If true incremental append operation is performed.IOException
- if a problem occurspublic void save() throws IOException
History
save
in interface History
IOException
- if a problem occursprotected void trimHistory(Path path, int max) throws IOException
IOException
protected DefaultHistory.EntryImpl createEntry(int index, Instant time, String line)
index
- index of history entrytime
- entry creation timeline
- the entry textpublic ListIterator<History.Entry> iterator(int index)
public Spliterator<History.Entry> spliterator()
spliterator
in interface Iterable<History.Entry>
public void resetIndex()
History
resetIndex
in interface History
public boolean moveToLast()
moveToLast
in interface History
public boolean moveTo(int index)
public boolean moveToFirst()
moveToFirst
in interface History
public void moveToEnd()
public String current()
public boolean previous()
public boolean next()