Class AbstractSequentialListItemChangeDetector<T>

java.lang.Object
com.irurueta.hermes.AbstractSequentialListItemChangeDetector<T>
Type Parameters:
T - type of items.
Direct Known Subclasses:
ComparableSequentialListItemChangeDetector, SequentialListItemChangeDetector

public abstract class AbstractSequentialListItemChangeDetector<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 when each change is applied sequentially to the old list.
  • Constructor Details

    • AbstractSequentialListItemChangeDetector

      public AbstractSequentialListItemChangeDetector()
  • 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. Notice that this method modifies the old items copy to avoid checking removed items again.
      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. Notice that this method modifies the old items copy to avoid checking inserted items again.
      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. Notice that this method modifies the old items copy to avoid checking moved items again.
      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.