<commit_before>package solutions.alterego.androidbound.support.android.adapters;

import android.support.v4.util.Pair;
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.ViewGroup;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.disposables.Disposables;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;
import io.reactivex.schedulers.Schedulers;
import solutions.alterego.androidbound.interfaces.IViewBinder;

import static android.support.v7.util.DiffUtil.calculateDiff;

public class BindableRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final IViewBinder mViewBinder;

    private int mItemTemplate;

    private boolean mUseParentLayoutParams;

    private Map<Class<?>, Integer> mTemplatesForObjects = new HashMap<>();

    private List mItemsSource = new ArrayList<>();

    private SparseArray<Class<?>> mObjectIndex;

    private RecyclerView.LayoutManager mLayoutManager;

    private Disposable mSetValuesDisposable = Disposables.disposed();

    private Disposable mRemoveItemsDisposable = Disposables.disposed();

    private Queue<List<?>> pendingUpdates =
            new ArrayDeque<>();

    private Disposable mAddValueDisposable = Disposables.disposed();

    public BindableRecyclerViewAdapter(IViewBinder vb, int itemTemplate, boolean useParentLayoutParams) {
        mViewBinder = vb;
        mItemTemplate = itemTemplate;
        mUseParentLayoutParams = useParentLayoutParams;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Class<?> clazz = mObjectIndex.get(viewType);
        int layoutRes = mItemTemplate;

        if (clazz != null && mTemplatesForObjects.containsKey(clazz)) {
            layoutRes = mTemplatesForObjects.get(clazz);
            mViewBinder.getLogger().verbose(
                    "BindableRecyclerViewAdapter creating VH for viewType = " + viewType + " i.e. class = " + clazz
                            + " using layoutRes = "
                            + layoutRes);
        } else if (layoutRes != 0) {
            mViewBinder.getLogger().verbose("BindableRecyclerViewAdapter creating VH using layoutRes = " + layoutRes);
        } else {
            mViewBinder.getLogger().error("BindableRecyclerViewAdapter cannot find templates for class = " + clazz
                    + ": did you call setTemplatesForObjects or set itemTemplate in XML?");
        }
        return new BindableRecyclerViewItemViewHolder(
                mViewBinder.inflate(parent.getContext(), null, layoutRes, parent, false), mViewBinder, parent);<commit_msg>added exception rethrowing to errors in BindableRecyclerViewAdapter<commit_after>package solutions.alterego.androidbound.support.android.adapters;

import android.support.v4.util.Pair;
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.ViewGroup;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.disposables.Disposables;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;
import io.reactivex.schedulers.Schedulers;
import solutions.alterego.androidbound.interfaces.IViewBinder;

import static android.support.v7.util.DiffUtil.calculateDiff;

public class BindableRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final IViewBinder mViewBinder;

    private int mItemTemplate;

    private boolean mUseParentLayoutParams;

    private Map<Class<?>, Integer> mTemplatesForObjects = new HashMap<>();

    private List mItemsSource = new ArrayList<>();

    private SparseArray<Class<?>> mObjectIndex;

    private RecyclerView.LayoutManager mLayoutManager;

    private Disposable mSetValuesDisposable = Disposables.disposed();

    private Disposable mRemoveItemsDisposable = Disposables.disposed();

    private Queue<List<?>> pendingUpdates =
            new ArrayDeque<>();

    private Disposable mAddValueDisposable = Disposables.disposed();

    public BindableRecyclerViewAdapter(IViewBinder vb, int itemTemplate, boolean useParentLayoutParams) {
        mViewBinder = vb;
        mItemTemplate = itemTemplate;
        mUseParentLayoutParams = useParentLayoutParams;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Class<?> clazz = mObjectIndex.get(viewType);
        int layoutRes = mItemTemplate;

        if (clazz != null && mTemplatesForObjects.containsKey(clazz)) {
            layoutRes = mTemplatesForObjects.get(clazz);
            mViewBinder.getLogger().verbose(
                    "BindableRecyclerViewAdapter creating VH for viewType = " + viewType + " i.e. class = " + clazz
                            + " using layoutRes = "
                            + layoutRes);
        } else if (layoutRes != 0) {
            mViewBinder.getLogger().verbose("BindableRecyclerViewAdapter creating VH using layoutRes = " + layoutRes);
        } else {
            String msg = "BindableRecyclerViewAdapter cannot find templates for class = " + clazz
                    + ": did you call setTemplatesForObjects or set itemTemplate in XML?";
            mViewBinder.getLogger().error(msg);
            if (mViewBinder.isDebugMode()) {
                throw new RuntimeException(msg);
            }
        }
        return new BindableRecyclerViewItemViewHolder(
                mViewBinder.inflate(parent.getContext(), null, layoutRes, parent, false), mViewBinder, parent);
{'fraction_non_alphanumeric': 0.08798972382787412, 'fraction_numerical': 0.0016056518946692357, 'mean_word_length': 3.6243504083147737, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7397903', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1716, 'n_words': 367}