java.lang.Object | ||
↳ | com.pnfsoftware.jeb.util.events.EventSource | |
↳ | com.pnfsoftware.jeb.util.collect.ItemHistory<T> |
Generic tracker of items, based on a simple history queue (get last, get next) model.
Typically, such objects are long-lived; internally, references to items are strong. Therefore, it is up to the user to make sure that referenced objects are not prevented from being garbage collected, should they be.
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.pnfsoftware.jeb.util.events.EventSource
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ItemHistory()
Create a history of 1 with a capacity of 100 and
cleanHistoryAfterIndex set to
true. | |||||||||||
ItemHistory(int capacity, boolean cleanHistoryAfterIndex)
Create a history object with the
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
add(T item)
Add an item to the history.
| ||||||||||
void | addAll(Collection<T> items) | ||||||||||
void |
capacity(int capacity)
Update the history capacity.
| ||||||||||
int |
capacity()
Get the history maximum capacity.
| ||||||||||
List<T> |
get()
Retrieve a copy of the history items.
| ||||||||||
T |
getAt(int newIndex, T updatedItem)
Set the position of the History at a particular index.
| ||||||||||
T | getMostRecent() | ||||||||||
T | getNext(T updatedItem) | ||||||||||
T | getNext() | ||||||||||
T | getPrevious(T updatedItem) | ||||||||||
T | getPrevious() | ||||||||||
boolean | hasNext() | ||||||||||
boolean | hasPrevious() | ||||||||||
T | peekNext() | ||||||||||
T | peekPrevious() | ||||||||||
int |
position()
Get the current history index.
| ||||||||||
boolean | remove(T item) | ||||||||||
void | reset() | ||||||||||
int | size() | ||||||||||
String | toString() |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.pnfsoftware.jeb.util.events.EventSource
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
com.pnfsoftware.jeb.util.events.IEventSource
|
Create a history of 1 with a capacity of 100 and cleanHistoryAfterIndex
set to
true.
Create a history object with the
capacity | maximum capacity, must be at least 1 |
---|---|
cleanHistoryAfterIndex | if true, recording an element into the history when the history index is not at the top will erase all elements after the index and add the new item at the top; if false, the item is inserted at the top regardless of where the history index was |
Add an item to the history. Note that any next item may be removed (based on
cleanHistoryAfterIndex constructor parameter, in particular, if getPrevious()
method
was called without restoring position)
Update the history capacity.
Get the history maximum capacity.
Retrieve a copy of the history items. The first item in the returned list is the oldest one.
Set the position of the History at a particular index.
newIndex | The new index of the history |
---|
Get the current history index. Navigating the history using getNext(), getPrevious(), or modifying the history using add(),remove(), etc. updates this pointer.