int indexInTypesOf(int position, @NonNull Object item) throws BinderNotFoundException { int index = typePool.firstIndexOf(item.getClass()); if (index != -1) { @SuppressWarnings("unchecked") Linker<Object> linker = (Linker<Object>) typePool.getLinker(index); return index + linker.index(position, item); } throw new BinderNotFoundException(item.getClass()); }
/** * Registers all of the contents in the specified type pool. If you have registered a * class, it will override the original binder(s). Note that the method is non-thread-safe * so that you should not use it in concurrent operation. * <p> * Note that the method should not be called after * {@link RecyclerView#setAdapter(RecyclerView.Adapter)}, or you have to call the setAdapter * again. * </p> * * @param pool type pool containing contents to be added to this adapter inner pool * @see #register(Class, ItemViewBinder) * @see #register(Class) */ public void registerAll(@NonNull final TypePool pool) { checkNotNull(pool); final int size = pool.size(); for (int i = 0; i < size; i++) { registerWithoutChecking( pool.getClass(i), pool.getItemViewBinder(i), pool.getLinker(i) ); } }