package com.google.android.gms.common.data; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.google.android.gms.common.annotation.KeepForSdk; import com.google.android.gms.common.internal.Preconditions; import com.google.errorprone.annotations.ResultIgnorabilityUnspecified; import java.util.ArrayList; @KeepForSdk /* loaded from: classes2.dex */ public abstract class EntityBuffer extends AbstractDataBuffer { private boolean zaa; private ArrayList zab; @KeepForSdk public EntityBuffer(@NonNull DataHolder dataHolder) { super(dataHolder); this.zaa = false; } private final void zab() { synchronized (this) { try { if (!this.zaa) { int count = ((DataHolder) Preconditions.checkNotNull(this.mDataHolder)).getCount(); ArrayList arrayList = new ArrayList(); this.zab = arrayList; if (count > 0) { arrayList.add(0); String primaryDataMarkerColumn = getPrimaryDataMarkerColumn(); String string = this.mDataHolder.getString(primaryDataMarkerColumn, 0, this.mDataHolder.getWindowIndex(0)); for (int i = 1; i < count; i++) { int windowIndex = this.mDataHolder.getWindowIndex(i); String string2 = this.mDataHolder.getString(primaryDataMarkerColumn, i, windowIndex); if (string2 == null) { throw new NullPointerException("Missing value for markerColumn: " + primaryDataMarkerColumn + ", at row: " + i + ", for window: " + windowIndex); } if (!string2.equals(string)) { this.zab.add(Integer.valueOf(i)); string = string2; } } } this.zaa = true; } } catch (Throwable th) { throw th; } } } @Override // com.google.android.gms.common.data.AbstractDataBuffer, com.google.android.gms.common.data.DataBuffer @NonNull @ResultIgnorabilityUnspecified @KeepForSdk public final T get(int i) { int intValue; int intValue2; zab(); int zaa = zaa(i); int i2 = 0; if (i >= 0 && i != this.zab.size()) { if (i == this.zab.size() - 1) { intValue = ((DataHolder) Preconditions.checkNotNull(this.mDataHolder)).getCount(); intValue2 = ((Integer) this.zab.get(i)).intValue(); } else { intValue = ((Integer) this.zab.get(i + 1)).intValue(); intValue2 = ((Integer) this.zab.get(i)).intValue(); } int i3 = intValue - intValue2; if (i3 == 1) { int zaa2 = zaa(i); int windowIndex = ((DataHolder) Preconditions.checkNotNull(this.mDataHolder)).getWindowIndex(zaa2); String childDataMarkerColumn = getChildDataMarkerColumn(); if (childDataMarkerColumn == null || this.mDataHolder.getString(childDataMarkerColumn, zaa2, windowIndex) != null) { i2 = 1; } } else { i2 = i3; } } return getEntry(zaa, i2); } @Nullable @KeepForSdk public String getChildDataMarkerColumn() { return null; } @Override // com.google.android.gms.common.data.AbstractDataBuffer, com.google.android.gms.common.data.DataBuffer @KeepForSdk public int getCount() { zab(); return this.zab.size(); } @NonNull @KeepForSdk public abstract T getEntry(int i, int i2); @NonNull @KeepForSdk public abstract String getPrimaryDataMarkerColumn(); public final int zaa(int i) { if (i >= 0 && i < this.zab.size()) { return ((Integer) this.zab.get(i)).intValue(); } throw new IllegalArgumentException("Position " + i + " is out of bounds for this buffer"); } }