// Path: common-rv-adapter/src/main/java/io/github/anotherme17/commonrvadapter/RvItemViewDelegate.java
// public interface RvItemViewDelegate<T> {
// 
//     /**
//      * 设置Item的LayoutId
//      */
//     public abstract
//     @LayoutRes
//     int getItemLayoutId();
// 
//     /**
//      * <P>通过 {@code position} 和 {@code itemData} 判断是否为该位置的Item <br/>
//      * 如果返回true 则将依次调用以下接口  <br/>
//      * {@link RvItemViewDelegate#onViewHolderCreated(Context, RvHolderHelper)} <br/>
//      * {@link RvItemViewDelegate#setItemChildListener(RvHolderHelper, int)}<br/>
//      * {@link RvItemViewDelegate#convert(Context, RvHolderHelper, int, Object)}<br/>
//      * </P>
//      *
//      * @param position Item的位置
//      * @param itemData Item的内容
//      * @return {@code true} - 是该位置的Item <br/>
//      * <code> false</code> - 不是该位置的Item
//      */
//     public abstract boolean isDelegate(int position, T itemData);
// 
//     /**
//      * Item被创建时调用
//      *
//      * @param context {@link Context} 上下文
//      * @param helper  {@link RvHolderHelper}
//      */
//     public abstract void onViewHolderCreated(Context context, RvHolderHelper helper);
// 
//     /**
//      * 设置Item内部ChildView 的监听 在 {@link io.github.anotherme17.commonrvadapter.adapter.RecyclerViewAdapter#onCreateViewHolder(ViewGroup, int)} 中调用
//      *
//      * @param helper   {@link RvHolderHelper}
//      * @param viewType Item 的 layoutId
//      */
//     public abstract void setItemChildListener(RvHolderHelper helper, int viewType);
// 
//     /**
//      * 在此为Item里的View 赋值
//      *
//      * @param context  {@link Context} 上下文
//      * @param helper   {@link RvHolderHelper}
//      * @param position Item的位置 不包括头和尾
//      * @param itemData Item的内容
//      */
//     public abstract void convert(Context context, RvHolderHelper helper, int position, T itemData);
// }
// 
// Path: common-rv-adapter/src/main/java/io/github/anotherme17/commonrvadapter/exception/DelegateAlreadyExistException.java
// public class DelegateAlreadyExistException extends RuntimeException {
// 
//     public DelegateAlreadyExistException(int viewType, RvItemViewDelegate delegate) {
//         super("An ItemViewDelegate is already registered for the viewTypeId = "
//                 + viewType
//                 + ". Already registered ItemViewDelegate is "
//                 + delegate);
//     }
// }
// 
// Path: common-rv-adapter/src/main/java/io/github/anotherme17/commonrvadapter/exception/DelegateNotFoundException.java
// public class DelegateNotFoundException extends RuntimeException {
// 
//     public DelegateNotFoundException() {
//         super("Can not Find any Delegate");
//     }
// 
//     public DelegateNotFoundException(RvItemViewDelegate delegate) {
//         super("Can not find ItemViewDelegate = " + delegate);
//     }
// 
//     public DelegateNotFoundException(@LayoutRes int layoutId) {
//         super("Can not find ItemViewDelegate Which Layout Id = " + layoutId);
//     }
// }


import android.support.annotation.LayoutRes;
import android.support.v4.util.SparseArrayCompat;
import io.github.anotherme17.commonrvadapter.RvItemViewDelegate;
import io.github.anotherme17.commonrvadapter.exception.DelegateAlreadyExistException;
import io.github.anotherme17.commonrvadapter.exception.DelegateNotFoundException;
package io.github.anotherme17.commonrvadapter.manager;




/**
 * ItemDelegate 帮助类
 *
 * @author anotherme17
 * @version 1.0.0
 */
public class RvDelegateManager<T> {

    protected SparseArrayCompat<RvItemViewDelegate<T>> mDelegates = new SparseArrayCompat<>();

    public void addDelegate(RvItemViewDelegate<T> delegate) {
        int viewType = delegate.getItemLayoutId();
        if (mDelegates.get(viewType) != null) {
            throw new DelegateAlreadyExistException(viewType, mDelegates.get(viewType));
        } else {
            mDelegates.put(viewType, delegate);
        }
    }

// Path: common-rv-adapter/src/main/java/io/github/anotherme17/commonrvadapter/RvItemViewDelegate.java
// public interface RvItemViewDelegate<T> {
// 
//     /**
//      * 设置Item的LayoutId
//      */
//     public abstract
//     @LayoutRes
//     int getItemLayoutId();
// 
//     /**
//      * <P>通过 {@code position} 和 {@code itemData} 判断是否为该位置的Item <br/>
//      * 如果返回true 则将依次调用以下接口  <br/>
//      * {@link RvItemViewDelegate#onViewHolderCreated(Context, RvHolderHelper)} <br/>
//      * {@link RvItemViewDelegate#setItemChildListener(RvHolderHelper, int)}<br/>
//      * {@link RvItemViewDelegate#convert(Context, RvHolderHelper, int, Object)}<br/>
//      * </P>
//      *
//      * @param position Item的位置
//      * @param itemData Item的内容
//      * @return {@code true} - 是该位置的Item <br/>
//      * <code> false</code> - 不是该位置的Item
//      */
//     public abstract boolean isDelegate(int position, T itemData);
// 
//     /**
//      * Item被创建时调用
//      *
//      * @param context {@link Context} 上下文
//      * @param helper  {@link RvHolderHelper}
//      */
//     public abstract void onViewHolderCreated(Context context, RvHolderHelper helper);
// 
//     /**
//      * 设置Item内部ChildView 的监听 在 {@link io.github.anotherme17.commonrvadapter.adapter.RecyclerViewAdapter#onCreateViewHolder(ViewGroup, int)} 中调用
//      *
//      * @param helper   {@link RvHolderHelper}
//      * @param viewType Item 的 layoutId
//      */
//     public abstract void setItemChildListener(RvHolderHelper helper, int viewType);
// 
//     /**
//      * 在此为Item里的View 赋值
//      *
//      * @param context  {@link Context} 上下文
//      * @param helper   {@link RvHolderHelper}
//      * @param position Item的位置 不包括头和尾
//      * @param itemData Item的内容
//      */
//     public abstract void convert(Context context, RvHolderHelper helper, int position, T itemData);
// }
// 
// Path: common-rv-adapter/src/main/java/io/github/anotherme17/commonrvadapter/exception/DelegateAlreadyExistException.java
// public class DelegateAlreadyExistException extends RuntimeException {
// 
//     public DelegateAlreadyExistException(int viewType, RvItemViewDelegate delegate) {
//         super("An ItemViewDelegate is already registered for the viewTypeId = "
//                 + viewType
//                 + ". Already registered ItemViewDelegate is "
//                 + delegate);
//     }
// }
// 
// Path: common-rv-adapter/src/main/java/io/github/anotherme17/commonrvadapter/exception/DelegateNotFoundException.java
// public class DelegateNotFoundException extends RuntimeException {
// 
//     public DelegateNotFoundException() {
//         super("Can not Find any Delegate");
//     }
// 
//     public DelegateNotFoundException(RvItemViewDelegate delegate) {
//         super("Can not find ItemViewDelegate = " + delegate);
//     }
// 
//     public DelegateNotFoundException(@LayoutRes int layoutId) {
//         super("Can not find ItemViewDelegate Which Layout Id = " + layoutId);
//     }
// }


// Path: common-rv-adapter/src/main/java/io/github/anotherme17/commonrvadapter/manager/RvDelegateManager.java
import android.support.annotation.LayoutRes;
import android.support.v4.util.SparseArrayCompat;
import io.github.anotherme17.commonrvadapter.RvItemViewDelegate;
import io.github.anotherme17.commonrvadapter.exception.DelegateAlreadyExistException;
import io.github.anotherme17.commonrvadapter.exception.DelegateNotFoundException;

package io.github.anotherme17.commonrvadapter.manager;




/**
 * ItemDelegate 帮助类
 *
 * @author anotherme17
 * @version 1.0.0
 */
public class RvDelegateManager<T> {

    protected SparseArrayCompat<RvItemViewDelegate<T>> mDelegates = new SparseArrayCompat<>();

    public void addDelegate(RvItemViewDelegate<T> delegate) {
        int viewType = delegate.getItemLayoutId();
        if (mDelegates.get(viewType) != null) {
            throw new DelegateAlreadyExistException(viewType, mDelegates.get(viewType));
        } else {
            mDelegates.put(viewType, delegate);
        }
    }

    public void addDelegate(RvItemViewDelegate<T>... delegates) {