AdapterDelegatesManager { public int getViewType(@NonNull AdapterDelegate<T> delegate) { if (delegate == null) { throw new NullPointerException("Delegate is null"); } int index = delegates.indexOfValue(delegate); if (index == -1) { return -1; } return delegates.keyAt(index); } 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 getViewType() { AdapterDelegatesManager<List> manager = new AdapterDelegatesManager<>(); try { manager.getViewType(null); Assert.fail("Nullpointer Exception expected"); } catch (NullPointerException e) { } SpyableAdapterDelegate<List> delegate1 = new SpyableAdapterDelegate<>(0); SpyableAdapterDelegate<List> delegate2 = new SpyableAdapterDelegate<>(1); Assert.assertEquals(-1, manager.getViewType(delegate1)); Assert.assertEquals(-1, manager.getViewType(delegate2)); manager.addDelegate(delegate1); manager.addDelegate(delegate2); Assert.assertEquals(0, manager.getViewType(delegate1)); Assert.assertEquals(1, manager.getViewType(delegate2)); SpyableAdapterDelegate<List> delegate3 = new SpyableAdapterDelegate<>(2); SpyableAdapterDelegate<List> delegate4 = new SpyableAdapterDelegate<>(3); manager.addDelegate(4, delegate4); Assert.assertEquals(4, manager.getViewType(delegate4)); manager.addDelegate(delegate3); Assert.assertEquals(3, manager.getViewType(delegate3)); }