Package com.irurueta.hermes
Class AbstractListItemChangeDetector<T>
java.lang.Object
com.irurueta.hermes.AbstractListItemChangeDetector<T>
- Type Parameters:
T
- type of items.
- Direct Known Subclasses:
ComparableListItemChangeDetector
,ListItemChangeDetector
Abstract 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).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate List<UpdatedListItemChange<T>>
buildChanges
(List<T> newItemsCopy, List<T> oldItemsCopy) Finds changed items and build a list of detected update changes.private List<InsertedListItemChange<T>>
buildInserts
(List<T> newItemsCopy, List<T> oldItemsCopy) Finds inserted items and build a list of detected insert changes.private List<MovedListItemChange<T>>
buildMoves
(List<T> newItemsCopy, List<T> oldItemsCopy) Finds moved items and build a list of detected move changes.private List<RemovedListItemChange<T>>
buildRemoves
(List<T> newItemsCopy, List<T> oldItemsCopy) Finds removed items and build a list of detected remove changes.detectChanges
(List<T> newItems, List<T> oldItems) Detects changes between two lists of items.protected abstract boolean
hasContentChanged
(T newItem, T oldItem) Determines whether the content of an item has changed.protected abstract int
Determines the index of an item in a list.protected abstract boolean
notContains
(List<T> items, T item) Determines whether an item is not contained in a list.
-
Constructor Details
-
AbstractListItemChangeDetector
public AbstractListItemChangeDetector()
-
-
Method Details
-
detectChanges
Detects changes between two lists of items.- Parameters:
newItems
- new items.oldItems
- old items.- Returns:
- a list of found changes.
- Throws:
IllegalArgumentException
- if any of the provided lists is null.
-
hasContentChanged
Determines whether the content of an item has changed.- 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.- 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.- 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.
-
buildRemoves
Finds removed items and build a list of detected remove changes.- Parameters:
newItemsCopy
- new items copy.oldItemsCopy
- old items copy.- Returns:
- a list of detected remove changes.
-
buildInserts
Finds inserted items and build a list of detected insert changes.- Parameters:
newItemsCopy
- new items copy.oldItemsCopy
- old items copy.- Returns:
- a list of detected insert changes.
-
buildMoves
Finds moved items and build a list of detected move changes.- Parameters:
newItemsCopy
- new items copy.oldItemsCopy
- old items copy.- Returns:
- a list of detected move changes.
-
buildChanges
Finds changed items and build a list of detected update changes.- Parameters:
newItemsCopy
- new items copy.oldItemsCopy
- old items copy.- Returns:
- a list of detected update changes.
-