Package org.jline.reader.impl.history
Class DefaultHistory
- java.lang.Object
-
- org.jline.reader.impl.history.DefaultHistory
-
- All Implemented Interfaces:
java.lang.Iterable<History.Entry>
,History
public class DefaultHistory extends java.lang.Object implements History
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
DefaultHistory.EntryImpl
private static class
DefaultHistory.HistoryFileData
-
Nested classes/interfaces inherited from interface org.jline.reader.History
History.Entry
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_HISTORY_FILE_SIZE
static int
DEFAULT_HISTORY_SIZE
private java.util.Map<java.lang.String,DefaultHistory.HistoryFileData>
historyFiles
private int
index
private java.util.LinkedList<History.Entry>
items
private int
offset
private LineReader
reader
-
Constructor Summary
Constructors Constructor Description DefaultHistory()
DefaultHistory(LineReader reader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.time.Instant time, java.lang.String line)
protected void
addHistoryLine(java.nio.file.Path path, java.lang.String line)
protected void
addHistoryLine(java.nio.file.Path path, java.lang.String line, boolean checkDuplicates)
void
append(java.nio.file.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, java.time.Instant time, java.lang.String line)
Create a history entry.java.lang.String
current()
Return the content of the current buffer.private java.lang.String
doHistoryFileDataKey(java.nio.file.Path path)
(package private) static java.util.List<History.Entry>
doTrimHistory(java.util.List<History.Entry> allItems, int max)
private static java.lang.String
escape(java.lang.String s)
int
first()
private java.lang.String
format(History.Entry entry)
java.lang.String
get(int index)
private int
getEntriesInFile(java.nio.file.Path path)
private DefaultHistory.HistoryFileData
getHistoryFileData(java.nio.file.Path path)
private int
getLastLoaded(java.nio.file.Path path)
private java.nio.file.Path
getPath()
private void
incEntriesInFile(java.nio.file.Path path, int amount)
int
index()
protected void
internalAdd(java.time.Instant time, java.lang.String line)
protected void
internalAdd(java.time.Instant time, java.lang.String line, boolean checkDuplicates)
private void
internalClear()
private void
internalWrite(java.nio.file.Path path, int from)
boolean
isEmpty()
private boolean
isLineReaderHistory(java.nio.file.Path path)
java.util.ListIterator<History.Entry>
iterator(int index)
int
last()
void
load()
Load history.protected boolean
matchPatterns(java.lang.String patterns, java.lang.String line)
private void
maybeResize()
boolean
moveTo(int index)
Move to the specified index in the historyvoid
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(java.nio.file.Path file, boolean incremental)
Read history from the file.void
resetIndex()
Reset index after removevoid
save()
Save history.private void
setEntriesInFile(java.nio.file.Path path, int entriesInFile)
private void
setHistoryFileData(java.nio.file.Path path, DefaultHistory.HistoryFileData historyFileData)
private void
setLastLoaded(java.nio.file.Path path, int lastloaded)
int
size()
java.util.Spliterator<History.Entry>
spliterator()
java.lang.String
toString()
protected void
trimHistory(java.nio.file.Path path, int max)
(package private) static java.lang.String
unescape(java.lang.String s)
void
write(java.nio.file.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
-
items
private final java.util.LinkedList<History.Entry> items
-
reader
private LineReader reader
-
historyFiles
private java.util.Map<java.lang.String,DefaultHistory.HistoryFileData> historyFiles
-
offset
private int offset
-
index
private int index
-
-
Constructor Detail
-
DefaultHistory
public DefaultHistory()
-
DefaultHistory
public DefaultHistory(LineReader reader)
-
-
Method Detail
-
getPath
private java.nio.file.Path getPath()
-
attach
public void attach(LineReader reader)
Description copied from interface:History
Initialize the history for the given reader.
-
load
public void load() throws java.io.IOException
Description copied from interface:History
Load history.
-
read
public void read(java.nio.file.Path file, boolean incremental) throws java.io.IOException
Description copied from interface:History
Read history from the file. If incremental only the events that are not contained within the internal list are added.
-
doHistoryFileDataKey
private java.lang.String doHistoryFileDataKey(java.nio.file.Path path)
-
getHistoryFileData
private DefaultHistory.HistoryFileData getHistoryFileData(java.nio.file.Path path)
-
setHistoryFileData
private void setHistoryFileData(java.nio.file.Path path, DefaultHistory.HistoryFileData historyFileData)
-
isLineReaderHistory
private boolean isLineReaderHistory(java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
setLastLoaded
private void setLastLoaded(java.nio.file.Path path, int lastloaded)
-
setEntriesInFile
private void setEntriesInFile(java.nio.file.Path path, int entriesInFile)
-
incEntriesInFile
private void incEntriesInFile(java.nio.file.Path path, int amount)
-
getLastLoaded
private int getLastLoaded(java.nio.file.Path path)
-
getEntriesInFile
private int getEntriesInFile(java.nio.file.Path path)
-
addHistoryLine
protected void addHistoryLine(java.nio.file.Path path, java.lang.String line)
-
addHistoryLine
protected void addHistoryLine(java.nio.file.Path path, java.lang.String line, boolean checkDuplicates)
-
purge
public void purge() throws java.io.IOException
Description copied from interface:History
Purge history.
-
write
public void write(java.nio.file.Path file, boolean incremental) throws java.io.IOException
Description copied from interface:History
Write history to the file. If incremental only the events that are new since the last incremental operation to the file are added.
-
append
public void append(java.nio.file.Path file, boolean incremental) throws java.io.IOException
Description copied from interface:History
Append history to the file. If incremental only the events that are new since the last incremental operation to the file are added.
-
save
public void save() throws java.io.IOException
Description copied from interface:History
Save history.
-
internalWrite
private void internalWrite(java.nio.file.Path path, int from) throws java.io.IOException
- Throws:
java.io.IOException
-
trimHistory
protected void trimHistory(java.nio.file.Path path, int max) throws java.io.IOException
- Throws:
java.io.IOException
-
createEntry
protected DefaultHistory.EntryImpl createEntry(int index, java.time.Instant time, java.lang.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
-
internalClear
private void internalClear()
-
doTrimHistory
static java.util.List<History.Entry> doTrimHistory(java.util.List<History.Entry> allItems, int max)
-
format
private java.lang.String format(History.Entry entry)
-
add
public void add(java.time.Instant time, java.lang.String line)
-
matchPatterns
protected boolean matchPatterns(java.lang.String patterns, java.lang.String line)
-
internalAdd
protected void internalAdd(java.time.Instant time, java.lang.String line)
-
internalAdd
protected void internalAdd(java.time.Instant time, java.lang.String line, boolean checkDuplicates)
-
maybeResize
private void maybeResize()
-
iterator
public java.util.ListIterator<History.Entry> iterator(int index)
-
spliterator
public java.util.Spliterator<History.Entry> spliterator()
- Specified by:
spliterator
in interfacejava.lang.Iterable<History.Entry>
-
resetIndex
public void resetIndex()
Description copied from interface:History
Reset index after remove- Specified by:
resetIndex
in interfaceHistory
-
moveToLast
public boolean moveToLast()
This moves the history to the last entry. This entry is one position before the moveToEnd() position.- Specified by:
moveToLast
in 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:
moveToFirst
in 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 java.lang.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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
escape
private static java.lang.String escape(java.lang.String s)
-
unescape
static java.lang.String unescape(java.lang.String s)
-
-