APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.org.jline.reader.impl.history

public Class DefaultHistory

extends Object
implements History
Class Inheritance
All Implemented Interfaces
jdk.internal.org.jline.reader.History, java.lang.Iterable
Imports
java.io.*, java.nio.file.*, java.time.DateTimeException, .Instant, java.util.*, jdk.internal.org.jline.reader.History, .LineReader, jdk.internal.org.jline.utils.Log

History using a file for persistent backing.

Implementers should install shutdown hook to call DefaultHistory#save to save history to disk.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
private static class

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
private Map<String, DefaultHistory.HistoryFileData>
private int
private final LinkedList<History.Entry>
private int
private LineReader

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
protected void
protected void
addHistoryLine(Path path, String line, boolean checkDuplicates)

public void
append(Path file, boolean incremental)

Implements jdk.internal.org.jline.reader.History.append.

Append history to the file.

public void
attach(LineReader reader)

Implements jdk.internal.org.jline.reader.History.attach.

Initialize the history for the given reader.

protected DefaultHistory.EntryImpl

Returns:

entry object
createEntry
(int
index of history entry
index
,
Instant
entry creation time
time
,
String
the entry text
line
)

Create a history entry.

public String
current()

Implements jdk.internal.org.jline.reader.History.current.

Return the content of the current buffer.

private String
pack-priv static List<History.Entry>
doTrimHistory(List<History.Entry> allItems, int max)

private static String
public int
private String
public String
get(final int index)

Implements jdk.internal.org.jline.reader.History.get.

private int
private DefaultHistory.HistoryFileData
private int
private Path
private void
incEntriesInFile(Path path, int amount)

public int
protected void
protected void
internalAdd(Instant time, String line, boolean checkDuplicates)

private void
private void
internalWrite(Path path, int from)

public boolean
private boolean
public ListIterator<History.Entry>
public int
public void
protected boolean
matchPatterns(String patterns, String line)

private void
public boolean
moveTo(int index)

Implements jdk.internal.org.jline.reader.History.moveTo.

Move to the specified index in the history

public void
moveToEnd()

Implements jdk.internal.org.jline.reader.History.moveToEnd.

Move to the end of the history buffer.

public boolean

Returns:

Return false if there are no iterator in the history or if the history is already at the beginning.
moveToFirst
()

Implements jdk.internal.org.jline.reader.History.moveToFirst.

Moves the history index to the first entry.

public boolean

Returns:

Returns false if there were no history iterator or the history index was already at the last entry.
moveToLast
()

Implements jdk.internal.org.jline.reader.History.moveToLast.

This moves the history to the last entry.

public boolean

Returns:

true if we successfully went to the next element
next
()

Implements jdk.internal.org.jline.reader.History.next.

Move the pointer to the next element in the buffer.

public boolean

Returns:

true if we successfully went to the previous element
previous
()

Implements jdk.internal.org.jline.reader.History.previous.

Move the pointer to the previous element in the buffer.

public void
public void
read(Path file, boolean checkDuplicates)

Implements jdk.internal.org.jline.reader.History.read.

Read history from the file.

public void
resetIndex()

Implements jdk.internal.org.jline.reader.History.resetIndex.

Reset index after remove

public void
private void
setEntriesInFile(Path path, int entriesInFile)

private void
private void
setLastLoaded(Path path, int lastloaded)

public int
public Spliterator<History.Entry>
spliterator()

Overrides default java.lang.Iterable.spliterator.

Creates a Spliterator over the elements described by this Iterable.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

protected void
trimHistory(Path path, int max)

pack-priv static String
public void
write(Path file, boolean incremental)

Implements jdk.internal.org.jline.reader.History.write.

Write history to the file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

DEFAULT_HISTORY_FILE_SIZEback to summary
public static final int DEFAULT_HISTORY_FILE_SIZE
DEFAULT_HISTORY_SIZEback to summary
public static final int DEFAULT_HISTORY_SIZE
historyFilesback to summary
private Map<String, DefaultHistory.HistoryFileData> historyFiles
indexback to summary
private int index
itemsback to summary
private final LinkedList<History.Entry> items
offsetback to summary
private int offset
readerback to summary
private LineReader reader

Constructor Detail

DefaultHistoryback to summary
public DefaultHistory()
DefaultHistoryback to summary
public DefaultHistory(LineReader reader)
Annotations
@SuppressWarnings:this-escape

Method Detail

addback to summary
public void add(Instant time, String line)

Implements jdk.internal.org.jline.reader.History.add.

Annotations
@Override
addHistoryLineback to summary
protected void addHistoryLine(Path path, String line)
addHistoryLineback to summary
protected void addHistoryLine(Path path, String line, boolean checkDuplicates)
appendback to summary
public void append(Path file, boolean incremental) throws IOException

Implements jdk.internal.org.jline.reader.History.append.

Doc from jdk.internal.org.jline.reader.History.append.

Append history to the file. If incremental only the events that are new since the last incremental operation to the file are added.

Annotations
@Override
Exceptions
IOException:
if a problem occurs
attachback to summary
public void attach(LineReader reader)

Implements jdk.internal.org.jline.reader.History.attach.

Doc from jdk.internal.org.jline.reader.History.attach.

Initialize the history for the given reader.

Annotations
@Override
createEntryback to summary
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:int

index of history entry

time:Instant

entry creation time

line:String

the entry text

Returns:DefaultHistory.EntryImpl

entry object

currentback to summary
public String current()

Implements jdk.internal.org.jline.reader.History.current.

Return the content of the current buffer.

doHistoryFileDataKeyback to summary
private String doHistoryFileDataKey(Path path)
doTrimHistoryback to summary
pack-priv static List<History.Entry> doTrimHistory(List<History.Entry> allItems, int max)
escapeback to summary
private static String escape(String s)
firstback to summary
public int first()

Implements jdk.internal.org.jline.reader.History.first.

formatback to summary
private String format(History.Entry entry)
getback to summary
public String get(final int index)

Implements jdk.internal.org.jline.reader.History.get.

getEntriesInFileback to summary
private int getEntriesInFile(Path path)
getHistoryFileDataback to summary
private DefaultHistory.HistoryFileData getHistoryFileData(Path path)
getLastLoadedback to summary
private int getLastLoaded(Path path)
getPathback to summary
private Path getPath()
incEntriesInFileback to summary
private void incEntriesInFile(Path path, int amount)
indexback to summary
public int index()

Implements jdk.internal.org.jline.reader.History.index.

internalAddback to summary
protected void internalAdd(Instant time, String line)
internalAddback to summary
protected void internalAdd(Instant time, String line, boolean checkDuplicates)
internalClearback to summary
private void internalClear()
internalWriteback to summary
private void internalWrite(Path path, int from) throws IOException
isEmptyback to summary
public boolean isEmpty()

Overrides default jdk.internal.org.jline.reader.History.isEmpty.

isLineReaderHistoryback to summary
private boolean isLineReaderHistory(Path path) throws IOException
iteratorback to summary
public ListIterator<History.Entry> iterator(int index)

Implements jdk.internal.org.jline.reader.History.iterator.

lastback to summary
public int last()

Implements jdk.internal.org.jline.reader.History.last.

loadback to summary
public void load() throws IOException

Implements jdk.internal.org.jline.reader.History.load.

Doc from jdk.internal.org.jline.reader.History.load.

Load history.

Annotations
@Override
Exceptions
IOException:
if a problem occurs
matchPatternsback to summary
protected boolean matchPatterns(String patterns, String line)
maybeResizeback to summary
private void maybeResize()
moveToback to summary
public boolean moveTo(int index)

Implements jdk.internal.org.jline.reader.History.moveTo.

Move to the specified index in the history

moveToEndback to summary
public void moveToEnd()

Implements jdk.internal.org.jline.reader.History.moveToEnd.

Move to the end of the history buffer. This will be a blank entry, after all of the other iterator.

moveToFirstback to summary
public boolean moveToFirst()

Implements jdk.internal.org.jline.reader.History.moveToFirst.

Moves the history index to the first entry.

Returns:boolean

Return false if there are no iterator in the history or if the history is already at the beginning.

moveToLastback to summary
public boolean moveToLast()

Implements jdk.internal.org.jline.reader.History.moveToLast.

This moves the history to the last entry. This entry is one position before the moveToEnd() position.

Returns:boolean

Returns false if there were no history iterator or the history index was already at the last entry.

nextback to summary
public boolean next()

Implements jdk.internal.org.jline.reader.History.next.

Move the pointer to the next element in the buffer.

Returns:boolean

true if we successfully went to the next element

previousback to summary
public boolean previous()

Implements jdk.internal.org.jline.reader.History.previous.

Move the pointer to the previous element in the buffer.

Returns:boolean

true if we successfully went to the previous element

purgeback to summary
public void purge() throws IOException

Implements jdk.internal.org.jline.reader.History.purge.

Doc from jdk.internal.org.jline.reader.History.purge.

Purge history.

Annotations
@Override
Exceptions
IOException:
if a problem occurs
readback to summary
public void read(Path file, boolean checkDuplicates) throws IOException

Implements jdk.internal.org.jline.reader.History.read.

Doc from jdk.internal.org.jline.reader.History.read.

Read history from the file. If checkDuplicates is true only the events that are not contained within the internal list are added.

Annotations
@Override
Exceptions
IOException:
if a problem occurs
resetIndexback to summary
public void resetIndex()

Implements jdk.internal.org.jline.reader.History.resetIndex.

Doc from jdk.internal.org.jline.reader.History.resetIndex.

Reset index after remove

saveback to summary
public void save() throws IOException

Implements jdk.internal.org.jline.reader.History.save.

Doc from jdk.internal.org.jline.reader.History.save.

Save history.

Annotations
@Override
Exceptions
IOException:
if a problem occurs
setEntriesInFileback to summary
private void setEntriesInFile(Path path, int entriesInFile)
setHistoryFileDataback to summary
private void setHistoryFileData(Path path, DefaultHistory.HistoryFileData historyFileData)
setLastLoadedback to summary
private void setLastLoaded(Path path, int lastloaded)
sizeback to summary
public int size()

Implements jdk.internal.org.jline.reader.History.size.

spliteratorback to summary
public Spliterator<History.Entry> spliterator()

Overrides default java.lang.Iterable.spliterator.

Doc from java.lang.Iterable.spliterator.

Creates a Spliterator over the elements described by this Iterable.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
trimHistoryback to summary
protected void trimHistory(Path path, int max) throws IOException
unescapeback to summary
pack-priv static String unescape(String s)
writeback to summary
public void write(Path file, boolean incremental) throws IOException

Implements jdk.internal.org.jline.reader.History.write.

Doc from jdk.internal.org.jline.reader.History.write.

Write history to the file. If incremental only the events that are new since the last incremental operation to the file are added.

Annotations
@Override
Exceptions
IOException:
if a problem occurs
jdk.internal.org.jline.reader.impl.history back to summary

protected Class DefaultHistory.EntryImpl

extends Object
implements Entry
Class Inheritance
  • java.lang.Object
  • jdk.internal.org.jline.reader.impl.history.DefaultHistory.EntryImpl
All Implemented Interfaces
jdk.internal.org.jline.reader.History.Entry

Field Summary

Modifier and TypeField and Description
private final int
private final String
private final Instant

Constructor Summary

AccessConstructor and Description
public
EntryImpl(int index, Instant time, String line)

Method Summary

Modifier and TypeMethod and Description
public int
public String
public Instant
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

indexback to summary
private final int index
lineback to summary
private final String line
timeback to summary
private final Instant time

Constructor Detail

EntryImplback to summary
public EntryImpl(int index, Instant time, String line)

Method Detail

indexback to summary
public int index()

Implements jdk.internal.org.jline.reader.History.Entry.index.

lineback to summary
public String line()

Implements jdk.internal.org.jline.reader.History.Entry.line.

timeback to summary
public Instant time()

Implements jdk.internal.org.jline.reader.History.Entry.time.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
jdk.internal.org.jline.reader.impl.history back to summary

private Class DefaultHistory.HistoryFileData

extends Object
Class Inheritance
  • java.lang.Object
  • jdk.internal.org.jline.reader.impl.history.DefaultHistory.HistoryFileData

Field Summary

Modifier and TypeField and Description
private int
private int

Constructor Summary

AccessConstructor and Description
public
public
HistoryFileData(int lastLoaded, int entriesInFile)

Method Summary

Modifier and TypeMethod and Description
public void
public int
public int
public void
incEntriesInFile(int amount)

public void
setEntriesInFile(int entriesInFile)

public void
setLastLoaded(int lastLoaded)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

entriesInFileback to summary
private int entriesInFile
lastLoadedback to summary
private int lastLoaded

Constructor Detail

HistoryFileDataback to summary
public HistoryFileData()
HistoryFileDataback to summary
public HistoryFileData(int lastLoaded, int entriesInFile)

Method Detail

decLastLoadedback to summary
public void decLastLoaded()
getEntriesInFileback to summary
public int getEntriesInFile()
getLastLoadedback to summary
public int getLastLoaded()
incEntriesInFileback to summary
public void incEntriesInFile(int amount)
setEntriesInFileback to summary
public void setEntriesInFile(int entriesInFile)
setLastLoadedback to summary
public void setLastLoaded(int lastLoaded)