<commit_before>package com.kogimobile.android.baselibrary.app.base.adapter;

import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.View;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import butterknife.ButterKnife;

/**
 * @author <NAME>. <EMAIL>
 * @version 9/4/16. *
 *          Copyright 2015 Kogi Mobile
 *          <p>
 *          Licensed under the Apache License, Version 2.0 (the "License");
 *          you may not use this file except in compliance with the License.
 *          You may obtain a copy of the License at
 *          <p>
 *          http://www.apache.org/licenses/LICENSE-2.0
 *          <p>
 *          Unless required by applicable law or agreed to in writing, software
 *          distributed under the License is distributed on an "AS IS" BASIS,
 *          WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *          See the License for the specific language governing permissions and
 *          limitations under the License.
 * @modified <NAME>. <EMAIL>
 */
public abstract class BaseSimpleAdapter<T, H extends BaseSimpleAdapter.BaseViewHolder> extends RecyclerView.Adapter<H> {

    protected static final int EMPTY_VIEW = 2000;
    protected static final int HEADER_VIEW = 3000;
    protected static final int LOADING_VIEW = 4000;
    protected static final int LOAD_MORE_VIEW = 5000;

    private List<T> items = new ArrayList<>();
    private onItemClickListener<T> clickListener;
    private ItemTouchHelperAdapter<T> itemTouchHelperAdapter;

    private int whereItemStartToMove;
    private int whereItemEndToMove;
    private boolean callbackMoved;
    private boolean callbackSwiped;

    private boolean headerView;
    private boolean isLoadMore;
    private boolean entryState = true;
    private boolean loadingState;

    public List<T> getItems() {
        return items;
    }

    @Override
    public int getItemCount() {
        validateItemsNullAndCreate();
        if (items.size() == 0) {
            return getPositionByRules();
        } else {
            return items.size() + getPositionByRules() + (haveLoadMoreView() ? 1 : 0);
        }
    }

    @Override
    public int getItemViewType(int position) {
        validateItemsNullAndCreate();

        if (haveToShowMore(position)) {
            return LOAD_MORE_VIEW;
        }

        if (haveAdapterHeaderView() && isEmptyState()) {
            if (items.size() == 0 && position == 1) {
                return isLoadingStateEnabled() ? LOADING_VIEW : EMPTY_VIEW;
            }
            if (items.size() >= 0 && position == 0) {
                return isLoadingStateEnabled() ? LOADING_VIEW : HEADER_VIEW;
            }
        }

        if (isEmptyState() && items.size() == 0) {
            return isLoadingStateEnabled() ? LOADING_VIEW : EMPTY_VIEW;
        }

        if (haveToShowHeader(position)) {
            return HEADER_VIEW;
        }

        return super.getItemViewType(position);

    }

    private boolean haveToShowHeader(int position) {
        return haveAdapterHeaderView() && items.size() >= 0 && position == 0;
    }

    private boolean haveToShowMore(int position) {
        return (position >= items.size() + getPositionByRules()) && haveLoadMoreView() && items.size() > 0;
    }

    private void validateItemsNullAndCreate() {
        if (items == null) {
            items = new ArrayList<>();
        }
    }

    /**
     * This method find an item adapter by position.
     *
     * @param position Where the item is in the list of base items.
     * @return The item that found in the position or null in case to don't founded.
     */
    public T getItem(int position) {
        if (items != null && position - getPositionByRules() < items.size()) {
            return items.get(position - getPositionByRules());
        }
        return null;
    }

    /**
     * This method clear the base list items and add the new list of items.
     * if you past a null the list of items go to create a new entry list.
     *
     * @param list list of items to insert in the base list of items in the adapter.
     */
    public void cleanItemsAndUpdate(@Nullable List<T> list) {
        validateItemsNullAndCreate();
        items.clear();
        addItems(list);
        notifyDataSetChanged();
    }

    /**
     * This method add the new list of items if you past a null.
     * the list of items go to create a new entry list.
     *
     * @param list list of items to add in the base list of items in the adapter.
     */
    public void addItems(@Nullable List<T> list) {
        validateItemsNullAndCreate();
        this.items.addAll(list == null ? new ArrayList<T>() : list);
        notifyDataSetChanged();
    }

    /**
     * This method find and remove an item adapter by position.
     *
     * @param item to remove in list.
     * @return The true in case to find and remove the items.
     */
    public boolean removeItem(@NonNull T item) {
        validateItemsNullAndCreate();
        if (items.remove(item)) {<commit_msg>update simple adapter<commit_after>package com.kogimobile.android.baselibrary.app.base.adapter;

import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.View;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import butterknife.ButterKnife;

/**
 * @author <NAME>. <EMAIL>
 * @version 9/4/16. *
 *          Copyright 2015 Kogi Mobile
 *          <p>
 *          Licensed under the Apache License, Version 2.0 (the "License");
 *          you may not use this file except in compliance with the License.
 *          You may obtain a copy of the License at
 *          <p>
 *          http://www.apache.org/licenses/LICENSE-2.0
 *          <p>
 *          Unless required by applicable law or agreed to in writing, software
 *          distributed under the License is distributed on an "AS IS" BASIS,
 *          WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *          See the License for the specific language governing permissions and
 *          limitations under the License.
 * @modified <NAME>. <EMAIL>
 */
public abstract class BaseSimpleAdapter<T, H extends BaseSimpleAdapter.BaseViewHolder> extends RecyclerView.Adapter<H> {

    protected static final int EMPTY_VIEW = 2000;
    protected static final int HEADER_VIEW = 3000;
    protected static final int LOADING_VIEW = 4000;
    protected static final int LOAD_MORE_VIEW = 5000;

    private List<T> items = new ArrayList<>();
    private onItemClickListener<T> clickListener;
    private ItemTouchHelperAdapter<T> itemTouchHelperAdapter;

    private int whereItemStartToMove;
    private int whereItemEndToMove;
    private boolean callbackMoved;
    private boolean callbackSwiped;

    private boolean headerView;
    private boolean isLoadMore;
    private boolean entryState = true;
    private boolean loadingState;

    public List<T> getItems() {
        return items;
    }

    @Override
    public int getItemCount() {
        validateItemsNullAndCreate();
        if (items.size() == 0) {
            return getPositionByRules();
        } else {
            return items.size() + getPositionByRules() + (haveLoadMoreView() ? 1 : 0);
        }
    }

    @Override
    public int getItemViewType(int position) {
        validateItemsNullAndCreate();

        if (haveToShowMore(position)) {
            return LOAD_MORE_VIEW;
        }

        if (haveAdapterHeaderView() && isEmptyState()) {
            if (items.size() == 0 && position == 1) {
                return isLoadingStateEnabled() ? LOADING_VIEW : EMPTY_VIEW;
            }
            if (items.size() >= 0 && position == 0) {
                return isLoadingStateEnabled() ? LOADING_VIEW : HEADER_VIEW;
            }
        }

        if (isEmptyState() && items.size() == 0) {
            return isLoadingStateEnabled() ? LOADING_VIEW : EMPTY_VIEW;
        }

        if (haveToShowHeader(position)) {
            return HEADER_VIEW;
        }

        return super.getItemViewType(position);

    }

    private boolean haveToShowHeader(int position) {
        return haveAdapterHeaderView() && items.size() >= 0 && position == 0;
    }

    private boolean haveToShowMore(int position) {
        return (position >= items.size() + getPositionByRules()) && haveLoadMoreView() && items.size() > 0;
    }

    private void validateItemsNullAndCreate() {
        if (items == null) {
            items = new ArrayList<>();
        }
    }

    /**
     * This method find an item adapter by position.
     *
     * @param position Where the item is in the list of base items.
     * @return The item that found in the position or null in case to don't founded.
     */
    public T getItem(int position) {
        if (items != null && position - getPositionByRules() < items.size()) {
            return items.get(position - getPositionByRules());
        }
        return null;
    }

    /**
     * This method clear the base list items and add the new list of items.
     * if you past a null the list of items go to create a new entry list.
     *
     * @param list list of items to insert in the base list of items in the adapter.
     */
    public void cleanItemsAndUpdate(@Nullable List<T> list) {
        validateItemsNullAndCreate();
        items.clear();
        addItems(list);
    }

    /**
     * This method add the new list of items if you past a null.
     * the list of items go to create a new entry list.
     *
     * @param list list of items to add in the base list of items in the adapter.
     */
    public void addItems(@Nullable List<T> list) {
        validateItemsNullAndCreate();
        this.items.addAll(list == null ? new ArrayList<T>() : list);
        notifyDataSetChanged();
    }

    /**
     * This method find and remove an item adapter by position.
     *
     * @param item to remove in list.
     * @return The true in case to find and remove the items.
     */
    public boolean removeItem(@NonNull T item) {
        validateItemsNullAndCreate();
        if (items.remove(item)) {
{'fraction_non_alphanumeric': 0.09258199847444698, 'fraction_numerical': 0.007818459191456904, 'mean_word_length': 2.4526003949967086, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '836052', 'n_tokens_mistral': 2901, 'n_tokens_neox': 2789, 'n_words': 947}