Rabbit-R1/android (non root)/java/sources/androidx/recyclerview/widget/TileList.java
2024-05-21 17:08:36 -04:00

87 lines
2.4 KiB
Java

package androidx.recyclerview.widget;
import android.util.SparseArray;
import java.lang.reflect.Array;
/* loaded from: classes2.dex */
class TileList<T> {
Tile<T> mLastAccessedTile;
final int mTileSize;
private final SparseArray<Tile<T>> mTiles = new SparseArray<>(10);
public TileList(int i) {
this.mTileSize = i;
}
public T getItemAt(int i) {
Tile<T> 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<T> getAtIndex(int i) {
if (i < 0 || i >= this.mTiles.size()) {
return null;
}
return this.mTiles.valueAt(i);
}
public Tile<T> addOrReplace(Tile<T> tile) {
int indexOfKey = this.mTiles.indexOfKey(tile.mStartPosition);
if (indexOfKey < 0) {
this.mTiles.put(tile.mStartPosition, tile);
return null;
}
Tile<T> valueAt = this.mTiles.valueAt(indexOfKey);
this.mTiles.setValueAt(indexOfKey, tile);
if (this.mLastAccessedTile == valueAt) {
this.mLastAccessedTile = tile;
}
return valueAt;
}
public Tile<T> removeAtPos(int i) {
Tile<T> 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<T> {
public int mItemCount;
public final T[] mItems;
Tile<T> 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<T> cls, int i) {
this.mItems = (T[]) ((Object[]) Array.newInstance((Class<?>) cls, i));
}
T getByPosition(int i) {
return this.mItems[i - this.mStartPosition];
}
}
}