This commit is contained in:
Denis Karmyshakov 2017-06-30 18:24:28 +03:00
parent eb17e79459
commit c7c9e80754
5 changed files with 48 additions and 0 deletions

View File

@ -22,8 +22,20 @@ package ru.touchin.roboswag.core.observables.collections.changes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
/**
* Functional interface for calculating change payload between two items same type.
* Payload calculating when items are same {@link SameItemsPredicate}, but content different.
*/
public interface ChangePayloadProducer<TItem> {
/**
* Calculate change payload between two items.
*
* @param item1 First item;
* @param item2 Second item;
* @return Object that represents minimal changes between two items.
*/
@Nullable
Object getChangePayload(@NonNull TItem item1, @NonNull TItem item2);

View File

@ -23,14 +23,32 @@ import android.support.annotation.NonNull;
import java.util.List;
/**
* Interface that represent changes calculator between two collections.
*/
public interface CollectionsChangesCalculator<TItem> {
/**
* Calculate changes between two collection as collection of objects {@link Change}.
*
* @return List of changes.
*/
@NonNull
List<Change> calculateChanges();
/**
* Calculate changes between two collection as collection of inserted items.
*
* @return List of inserted item.
*/
@NonNull
List<TItem> calculateInsertedItems();
/**
* Calculate changes between two collection as collection of removed items.
*
* @return List of removed item.
*/
@NonNull
List<TItem> calculateRemovedItems();

View File

@ -25,6 +25,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Default calculator between two collections that use equals function.
*/
public class DefaultCollectionsChangesCalculator<TItem> implements CollectionsChangesCalculator<TItem> {
@NonNull

View File

@ -28,6 +28,9 @@ import java.util.List;
import ru.touchin.roboswag.core.android.support.v7.util.DiffUtil;
import ru.touchin.roboswag.core.android.support.v7.util.ListUpdateCallback;
/**
* Implementation of {@link CollectionsChangesCalculator} based on DiffUtils from support library.
*/
public class DiffCollectionsChangesCalculator<TItem> extends DiffUtil.Callback implements CollectionsChangesCalculator<TItem> {
@NonNull

View File

@ -21,8 +21,20 @@ package ru.touchin.roboswag.core.observables.collections.changes;
import android.support.annotation.NonNull;
/**
* Functional interface for determine same objects. Usually this is just the comparison by id.
*
* @param <TItem> Type of objects
*/
public interface SameItemsPredicate<TItem> {
/**
* Function for determine same objects.
*
* @param item1 First object;
* @param item2 Second object;
* @return True if items are same.
*/
boolean areSame(@NonNull TItem item1, @NonNull TItem item2);
}