AdapterDelegatesManager { public AdapterDelegatesManager<T> addDelegate(@NonNull AdapterDelegate<T> delegate) { int viewType = delegates.size(); while (delegates.get(viewType) != null) { viewType++; if (viewType == FALLBACK_DELEGATE_VIEW_TYPE) { throw new IllegalArgumentException( "Oops, we are very close to Integer.MAX_VALUE. It seems that there are no more free and unused view type integers left to add another AdapterDelegate."); } } return addDelegate(viewType, false, delegate); } AdapterDelegatesManager();  AdapterDelegatesManager(@NonNull AdapterDelegate<T>... delegates); AdapterDelegatesManager<T> addDelegate(@NonNull AdapterDelegate<T> delegate); AdapterDelegatesManager<T> addDelegate(int viewType,
                                                  @NonNull AdapterDelegate<T> delegate); AdapterDelegatesManager<T> addDelegate(int viewType, boolean allowReplacingDelegate,
                                                  @NonNull AdapterDelegate<T> delegate); AdapterDelegatesManager<T> removeDelegate(@NonNull AdapterDelegate<T> delegate); AdapterDelegatesManager<T> removeDelegate(int viewType); int getItemViewType(@NonNull T items, int position); @NonNull RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType); void onBindViewHolder(@NonNull T items, int position,
                                 @NonNull RecyclerView.ViewHolder holder, List payloads); void onBindViewHolder(@NonNull T items, int position,
                                 @NonNull RecyclerView.ViewHolder holder); void onViewRecycled(@NonNull RecyclerView.ViewHolder holder); boolean onFailedToRecycleView(@NonNull RecyclerView.ViewHolder holder); void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder); void onViewDetachedFromWindow(@NonNull RecyclerView.ViewHolder holder); AdapterDelegatesManager<T> setFallbackDelegate(
            @Nullable AdapterDelegate<T> fallbackDelegate); int getViewType(@NonNull AdapterDelegate<T> delegate); @Nullable AdapterDelegate<T> getDelegateForViewType(int viewType); @Nullable AdapterDelegate<T> getFallbackDelegate(); static final int FALLBACK_DELEGATE_VIEW_TYPE; }
@Test public void viewTypeInConflictWithFallbackDelegate() { try { AdapterDelegatesManager<List> manager = new AdapterDelegatesManager<>(); manager.addDelegate(AdapterDelegatesManager.FALLBACK_DELEGATE_VIEW_TYPE, new SpyableAdapterDelegate<List>(0)); Assert.fail( "An exception should be thrown because view type integer is already reserved for fallback delegate"); } catch (IllegalArgumentException e) { Assert.assertEquals("The view type = " + AdapterDelegatesManager.FALLBACK_DELEGATE_VIEW_TYPE + " is reserved for fallback adapter delegate (see setFallbackDelegate() ). Please use another view type.", e.getMessage()); } }