Class ListItemChangeDetector<T>

java.lang.Object
com.irurueta.hermes.AbstractListItemChangeDetector<T>
com.irurueta.hermes.ListItemChangeDetector<T>
Type Parameters:
T - type of items.

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

    • itemComparator

      private final ItemComparator<T> itemComparator
      Comparator to determine whether two items are equal (e.g., by their id).
    • itemContentComparator

      private final ItemContentComparator<T> 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

      protected boolean hasContentChanged(T newItem, T oldItem)
      Determines whether the content of an item has changed.
      Specified by:
      hasContentChanged in class AbstractListItemChangeDetector<T>
      Parameters:
      newItem - new item.
      oldItem - old item.
      Returns:
      true if the content of the item has changed, false otherwise.
    • notContains

      protected boolean notContains(List<T> items, T item)
      Determines whether an item is not contained in a list.
      Specified by:
      notContains in class AbstractListItemChangeDetector<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

      protected int indexOf(List<T> items, T item)
      Determines the index of an item in a list.
      Specified by:
      indexOf in class AbstractListItemChangeDetector<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.