Skip to content

Instantly share code, notes, and snippets.

@NikolaDespotoski
Created August 29, 2016 14:04
Show Gist options
  • Save NikolaDespotoski/720c8bf1fa0aed1f3140d594f1e289f8 to your computer and use it in GitHub Desktop.
Save NikolaDespotoski/720c8bf1fa0aed1f3140d594f1e289f8 to your computer and use it in GitHub Desktop.
import android.support.annotation.Nullable;
import android.support.v7.util.SortedList;
import java.util.Comparator;
/**
* Created by Nikola D. on 8/29/2016.
*/
public class ComparatorBatchedCallback<T> extends SortedList.BatchedCallback<T> {
@Nullable
private Comparator<T> mComparator;
/**
* Creates a new BatchedCallback that wraps the provided Callback.
*
* @param wrappedCallback The Callback which should received the data change callbacks.
* Other method calls (e.g. {@link #compare(Object, Object)} from
* the SortedList are directly forwarded to this Callback.
*/
public ComparatorBatchedCallback(SortedList.Callback<T> wrappedCallback) {
super(wrappedCallback);
}
@Override
public int compare(T o1, T o2) {
return mComparator != null ? mComparator.compare(o1, o2) : super.compare(o1, o2);
}
public void setComparator(@Nullable Comparator<T> comparator) {
mComparator = comparator;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment