Class AbstractListItemChangeDetector<T>

java.lang.Object
com.irurueta.hermes.AbstractListItemChangeDetector<T>
Type Parameters:
T - type of items.
Direct Known Subclasses:
ComparableListItemChangeDetector, ListItemChangeDetector

public abstract class AbstractListItemChangeDetector<T> extends Object
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 Details

    • AbstractListItemChangeDetector

      public AbstractListItemChangeDetector()
  • Method Details

    • detectChanges

      public List<ListItemChange> detectChanges(List<T> newItems, List<T> oldItems)
      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

      protected abstract boolean hasContentChanged(T newItem, T oldItem)
      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

      protected abstract boolean notContains(List<T> items, T item)
      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

      protected abstract int indexOf(List<T> items, T item)
      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

      private List<RemovedListItemChange<T>> buildRemoves(List<T> newItemsCopy, List<T> oldItemsCopy)
      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

      private List<InsertedListItemChange<T>> buildInserts(List<T> newItemsCopy, List<T> oldItemsCopy)
      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

      private List<MovedListItemChange<T>> buildMoves(List<T> newItemsCopy, List<T> oldItemsCopy)
      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

      private List<UpdatedListItemChange<T>> buildChanges(List<T> newItemsCopy, List<T> oldItemsCopy)
      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.