- java.lang.Object
-
- org.jline.reader.impl.history.DefaultHistory
-
- All Implemented Interfaces:
Iterable<History.Entry>,History
public class DefaultHistory extends Object implements History
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDefaultHistory.EntryImpl-
Nested classes/interfaces inherited from interface org.jline.reader.History
History.Entry
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_HISTORY_FILE_SIZEstatic intDEFAULT_HISTORY_SIZE
-
Constructor Summary
Constructors Constructor Description DefaultHistory()DefaultHistory(LineReader reader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Instant time, String line)protected voidaddHistoryLine(Path path, String line)protected voidaddHistoryLine(Path path, String line, boolean checkDuplicates)voidappend(Path file, boolean incremental)Append history to the file.voidattach(LineReader reader)Initialize the history for the given reader.protected DefaultHistory.EntryImplcreateEntry(int index, Instant time, String line)Create a history entry.Stringcurrent()Return the content of the current buffer.intfirst()Stringget(int index)intindex()protected voidinternalAdd(Instant time, String line)protected voidinternalAdd(Instant time, String line, boolean checkDuplicates)booleanisEmpty()ListIterator<History.Entry>iterator(int index)intlast()voidload()Load history.protected booleanmatchPatterns(String patterns, String line)booleanmoveTo(int index)Move to the specified index in the historyvoidmoveToEnd()Move to the end of the history buffer.booleanmoveToFirst()Moves the history index to the first entry.booleanmoveToLast()This moves the history to the last entry.booleannext()Move the pointer to the next element in the buffer.booleanprevious()Move the pointer to the previous element in the buffer.voidpurge()Purge history.voidread(Path file, boolean checkDuplicates)Read history from the file.voidresetIndex()Reset index after removevoidsave()Save history.intsize()Spliterator<History.Entry>spliterator()StringtoString()protected voidtrimHistory(Path path, int max)voidwrite(Path file, boolean incremental)Write history to the file.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jline.reader.History
add, isPersistable, iterator, reverseIterator, reverseIterator
-
-
-
-
Field Detail
-
DEFAULT_HISTORY_SIZE
public static final int DEFAULT_HISTORY_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_HISTORY_FILE_SIZE
public static final int DEFAULT_HISTORY_FILE_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultHistory
public DefaultHistory()
-
DefaultHistory
public DefaultHistory(LineReader reader)
-
-
Method Detail
-
attach
public void attach(LineReader reader)
Description copied from interface:HistoryInitialize the history for the given reader.
-
load
public void load() throws IOExceptionDescription copied from interface:HistoryLoad history.- Specified by:
loadin interfaceHistory- Throws:
IOException- if a problem occurs
-
read
public void read(Path file, boolean checkDuplicates) throws IOException
Description copied from interface:HistoryRead history from the file. If checkDuplicates istrueonly the events that are not contained within the internal list are added.- Specified by:
readin interfaceHistory- Parameters:
file- History filecheckDuplicates- Iftrue, duplicate history entries will be discarded- Throws:
IOException- if a problem occurs
-
purge
public void purge() throws IOExceptionDescription copied from interface:HistoryPurge history.- Specified by:
purgein interfaceHistory- Throws:
IOException- if a problem occurs
-
write
public void write(Path file, boolean incremental) throws IOException
Description copied from interface:HistoryWrite history to the file. If incremental only the events that are new since the last incremental operation to the file are added.- Specified by:
writein interfaceHistory- Parameters:
file- History fileincremental- If true incremental write operation is performed.- Throws:
IOException- if a problem occurs
-
append
public void append(Path file, boolean incremental) throws IOException
Description copied from interface:HistoryAppend history to the file. If incremental only the events that are new since the last incremental operation to the file are added.- Specified by:
appendin interfaceHistory- Parameters:
file- History fileincremental- If true incremental append operation is performed.- Throws:
IOException- if a problem occurs
-
save
public void save() throws IOExceptionDescription copied from interface:HistorySave history.- Specified by:
savein interfaceHistory- Throws:
IOException- if a problem occurs
-
trimHistory
protected void trimHistory(Path path, int max) throws IOException
- Throws:
IOException
-
createEntry
protected DefaultHistory.EntryImpl createEntry(int index, Instant time, String line)
Create a history entry. Subclasses may override to use their own entry implementations.- Parameters:
index- index of history entrytime- entry creation timeline- the entry text- Returns:
- entry object
-
iterator
public ListIterator<History.Entry> iterator(int index)
-
spliterator
public Spliterator<History.Entry> spliterator()
- Specified by:
spliteratorin interfaceIterable<History.Entry>
-
resetIndex
public void resetIndex()
Description copied from interface:HistoryReset index after remove- Specified by:
resetIndexin interfaceHistory
-
moveToLast
public boolean moveToLast()
This moves the history to the last entry. This entry is one position before the moveToEnd() position.- Specified by:
moveToLastin interfaceHistory- Returns:
- Returns false if there were no history iterator or the history index was already at the last entry.
-
moveTo
public boolean moveTo(int index)
Move to the specified index in the history
-
moveToFirst
public boolean moveToFirst()
Moves the history index to the first entry.- Specified by:
moveToFirstin interfaceHistory- Returns:
- Return false if there are no iterator in the history or if the history is already at the beginning.
-
moveToEnd
public void moveToEnd()
Move to the end of the history buffer. This will be a blank entry, after all of the other iterator.
-
current
public String current()
Return the content of the current buffer.
-
previous
public boolean previous()
Move the pointer to the previous element in the buffer.
-
next
public boolean next()
Move the pointer to the next element in the buffer.
-
-