package androidx.recyclerview.widget; import android.util.SparseArray; import java.lang.reflect.Array; /* loaded from: classes2.dex */ class TileList { Tile mLastAccessedTile; final int mTileSize; private final SparseArray> mTiles = new SparseArray<>(10); public TileList(int i) { this.mTileSize = i; } public T getItemAt(int i) { Tile tile = this.mLastAccessedTile; if (tile == null || !tile.containsPosition(i)) { int indexOfKey = this.mTiles.indexOfKey(i - (i % this.mTileSize)); if (indexOfKey < 0) { return null; } this.mLastAccessedTile = this.mTiles.valueAt(indexOfKey); } return this.mLastAccessedTile.getByPosition(i); } public int size() { return this.mTiles.size(); } public void clear() { this.mTiles.clear(); } public Tile getAtIndex(int i) { if (i < 0 || i >= this.mTiles.size()) { return null; } return this.mTiles.valueAt(i); } public Tile addOrReplace(Tile tile) { int indexOfKey = this.mTiles.indexOfKey(tile.mStartPosition); if (indexOfKey < 0) { this.mTiles.put(tile.mStartPosition, tile); return null; } Tile valueAt = this.mTiles.valueAt(indexOfKey); this.mTiles.setValueAt(indexOfKey, tile); if (this.mLastAccessedTile == valueAt) { this.mLastAccessedTile = tile; } return valueAt; } public Tile removeAtPos(int i) { Tile tile = this.mTiles.get(i); if (this.mLastAccessedTile == tile) { this.mLastAccessedTile = null; } this.mTiles.delete(i); return tile; } /* loaded from: classes2.dex */ public static class Tile { public int mItemCount; public final T[] mItems; Tile mNext; public int mStartPosition; boolean containsPosition(int i) { int i2 = this.mStartPosition; return i2 <= i && i < i2 + this.mItemCount; } /* JADX INFO: Access modifiers changed from: package-private */ public Tile(Class cls, int i) { this.mItems = (T[]) ((Object[]) Array.newInstance((Class) cls, i)); } T getByPosition(int i) { return this.mItems[i - this.mStartPosition]; } } }