Package com.irurueta.hermes
Class ListItemChangeDetector<T>
java.lang.Object
com.irurueta.hermes.AbstractListItemChangeDetector<T>
com.irurueta.hermes.ListItemChangeDetector<T>
- Type Parameters:
T
- type of items.
Class to detect changes between two lists of items.
Notice that returned changes in this class indicate the positions of the items with respect to the old or the new
list (regardless of the order in which the change is applied).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ItemComparator<T>
Comparator to determine whether two items are equal (e.g., by their id).private final ItemContentComparator<T>
Comparator to determine whether the content of two items is equal. -
Constructor Summary
ConstructorsConstructorDescriptionListItemChangeDetector
(ItemComparator<T> itemComparator, ItemContentComparator<T> itemContentComparator) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
hasContentChanged
(T newItem, T oldItem) Determines whether the content of an item has changed.protected int
Determines the index of an item in a list.protected boolean
notContains
(List<T> items, T item) Determines whether an item is not contained in a list.Methods inherited from class com.irurueta.hermes.AbstractListItemChangeDetector
detectChanges
-
Field Details
-
itemComparator
Comparator to determine whether two items are equal (e.g., by their id). -
itemContentComparator
Comparator to determine whether the content of two items is equal.
-
-
Constructor Details
-
ListItemChangeDetector
public ListItemChangeDetector(ItemComparator<T> itemComparator, ItemContentComparator<T> itemContentComparator) Constructor.- Parameters:
itemComparator
- comparator to determine whether two items are equal.itemContentComparator
- comparator to determine whether the content of two items is equal.- Throws:
IllegalArgumentException
- if any of the parameters is null.
-
-
Method Details
-
hasContentChanged
Determines whether the content of an item has changed.- Specified by:
hasContentChanged
in classAbstractListItemChangeDetector<T>
- Parameters:
newItem
- new item.oldItem
- old item.- Returns:
- true if the content of the item has changed, false otherwise.
-
notContains
Determines whether an item is not contained in a list.- Specified by:
notContains
in classAbstractListItemChangeDetector<T>
- Parameters:
items
- list of items.item
- item to be checked.- Returns:
- true if the item is not contained in the list, false otherwise.
-
indexOf
Determines the index of an item in a list.- Specified by:
indexOf
in classAbstractListItemChangeDetector<T>
- Parameters:
items
- list of items.item
- item to be checked.- Returns:
- index of the item in the list, or -1 if the item is not contained in the list.
-