Top Description Fields Constructors Methods
com.dlsc.gemsfx.util

public abstract Class HistoryManager<T>

extends Object
Class Inheritance
Known Direct Subclasses
com.dlsc.gemsfx.util.InMemoryHistoryManager, com.dlsc.gemsfx.util.PreferencesHistoryManager
Type Parameters
<T>
the type of items stored in the history
Imports
javafx.beans.Observable, javafx.beans.property.IntegerProperty, .ObjectProperty, .SimpleIntegerProperty, .SimpleObjectProperty, javafx.collections.FXCollections, .ObservableList, java.util.List, .Objects, java.util.function.Predicate, java.util.logging.Logger

The HistoryManager class defines the standard operations to manage history storage for any type of items, allowing for implementation of various data storage mechanisms.

Field Summary

Modifier and TypeField and Description
private static final int
private final ObjectProperty<Predicate<T>>
private final ObservableList<T>
private static final Logger
private final IntegerProperty
private final ObservableList<T>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final void
add(T
the item to add
item
)

Adds the given item to the history.

public final void
add(List<T>
the items to add
items
)

Adds the given items to the history.

public final void
clear()

Clears the history.

private List<T>

Returns:

the converted unique list of strings
convertToUniqueList
(List<T>
the list of strings to convert
history
)

Converts a given list of strings to a unique list of strings.

public final ObjectProperty<Predicate<T>>

Returns:

the property object for the filter
filterProperty
()

Returns the property object for the filter used when adding items to the history.

public final ObservableList<T>
getAllUnmodifiable()

Returns an unmodifiable list of the history.

public final Predicate<T>
public final int
protected abstract void
public final IntegerProperty

Returns:

the maximum number of items in the history
maxHistorySizeProperty
()

The maximum number of items that the history will store.

public final boolean

Returns:

true if the item was removed, false otherwise
remove
(T
the item to remove
item
)

Removes the given item from the history.

public final void
remove(List<T>
the items to remove
items
)

Removes the given items from the history.

public final void
set(List<T>
the list of strings representing the history
history
)

Sets the history of the HistoryManager with the provided list of strings.

public final void
setFilter(Predicate<T> filter)

public final void
setMaxHistorySize(int maxHistorySize)

protected abstract void
private void
trimHistory()

Trims the history list to ensure it does not exceed the maximum allowed size.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_MAX_HISTORY_SIZEback to summary
private static final int DEFAULT_MAX_HISTORY_SIZE
filterback to summary
private final ObjectProperty<Predicate<T>> filter
historyback to summary
private final ObservableList<T> history
LOGback to summary
private static final Logger LOG
maxHistorySizeback to summary
private final IntegerProperty maxHistorySize
unmodifiableHistoryback to summary
private final ObservableList<T> unmodifiableHistory

Constructor Detail

HistoryManagerback to summary
public HistoryManager()

Method Detail

addback to summary
public final void add(T item)

Adds the given item to the history. The method ensures that duplicates will not be added.

Parameters
item:T

the item to add

addback to summary
public final void add(List<T> items)

Adds the given items to the history.

Parameters
items:List<T>

the items to add

clearback to summary
public final void clear()

Clears the history.

convertToUniqueListback to summary
private List<T> convertToUniqueList(List<T> history)

Converts a given list of strings to a unique list of strings. Filters out empty strings.

Parameters
history:List<T>

the list of strings to convert

Returns:List<T>

the converted unique list of strings

filterPropertyback to summary
public final ObjectProperty<Predicate<T>> filterProperty()

Returns the property object for the filter used when adding items to the history. Only items that pass the filter will be added to the history.

Returns:ObjectProperty<Predicate<T>>

the property object for the filter

getAllUnmodifiableback to summary
public final ObservableList<T> getAllUnmodifiable()

Returns an unmodifiable list of the history.

getFilterback to summary
public final Predicate<T> getFilter()
getMaxHistorySizeback to summary
public final int getMaxHistorySize()
loadHistoryback to summary
protected abstract void loadHistory()
maxHistorySizePropertyback to summary
public final IntegerProperty maxHistorySizeProperty()

The maximum number of items that the history will store. If the number of items exceeds this value, the oldest items will be removed.

Returns:IntegerProperty

the maximum number of items in the history

removeback to summary
public final boolean remove(T item)

Removes the given item from the history.

Parameters
item:T

the item to remove

Returns:boolean

true if the item was removed, false otherwise

removeback to summary
public final void remove(List<T> items)

Removes the given items from the history.

Parameters
items:List<T>

the items to remove

setback to summary
public final void set(List<T> history)

Sets the history of the HistoryManager with the provided list of strings. The method ensures that duplicates are removed from the list.

Parameters
history:List<T>

the list of strings representing the history

setFilterback to summary
public final void setFilter(Predicate<T> filter)
setMaxHistorySizeback to summary
public final void setMaxHistorySize(int maxHistorySize)
storeHistoryback to summary
protected abstract void storeHistory()
trimHistoryback to summary
private void trimHistory()

Trims the history list to ensure it does not exceed the maximum allowed size. If the current history size is greater than the maximum size, the method removes the extra elements from the history list.