package com.google.android.gms.vision; import android.util.SparseArray; import com.google.android.gms.vision.Detector; import java.util.HashSet; import java.util.Iterator; /* loaded from: classes2.dex */ public class MultiProcessor implements Detector.Processor { private int zzal; private Factory zzaz; private SparseArray zzba; /* loaded from: classes2.dex */ public interface Factory { Tracker create(T t); } @Override // com.google.android.gms.vision.Detector.Processor public void release() { for (int i = 0; i < this.zzba.size(); i++) { this.zzba.valueAt(i).zzak.onDone(); } this.zzba.clear(); } /* loaded from: classes2.dex */ final class zza { private Tracker zzak; private int zzao; private zza(MultiProcessor multiProcessor) { this.zzao = 0; } static /* synthetic */ int zzb(zza zzaVar) { int i = zzaVar.zzao; zzaVar.zzao = i + 1; return i; } static /* synthetic */ int zza(zza zzaVar, int i) { zzaVar.zzao = 0; return 0; } } /* loaded from: classes2.dex */ public static class Builder { private MultiProcessor zzbb; public Builder(Factory factory) { MultiProcessor multiProcessor = new MultiProcessor<>(); this.zzbb = multiProcessor; if (factory == null) { throw new IllegalArgumentException("No factory supplied."); } ((MultiProcessor) multiProcessor).zzaz = factory; } public Builder setMaxGapFrames(int i) { if (i < 0) { StringBuilder sb = new StringBuilder(28); sb.append("Invalid max gap: "); sb.append(i); throw new IllegalArgumentException(sb.toString()); } ((MultiProcessor) this.zzbb).zzal = i; return this; } public MultiProcessor build() { return this.zzbb; } } @Override // com.google.android.gms.vision.Detector.Processor public void receiveDetections(Detector.Detections detections) { SparseArray detectedItems = detections.getDetectedItems(); for (int i = 0; i < detectedItems.size(); i++) { int keyAt = detectedItems.keyAt(i); T valueAt = detectedItems.valueAt(i); if (this.zzba.get(keyAt) == null) { zza zzaVar = new zza(); zzaVar.zzak = this.zzaz.create(valueAt); zzaVar.zzak.onNewItem(keyAt, valueAt); this.zzba.append(keyAt, zzaVar); } } SparseArray detectedItems2 = detections.getDetectedItems(); HashSet hashSet = new HashSet(); for (int i2 = 0; i2 < this.zzba.size(); i2++) { int keyAt2 = this.zzba.keyAt(i2); if (detectedItems2.get(keyAt2) == null) { zza valueAt2 = this.zzba.valueAt(i2); zza.zzb(valueAt2); if (valueAt2.zzao >= this.zzal) { valueAt2.zzak.onDone(); hashSet.add(Integer.valueOf(keyAt2)); } else { valueAt2.zzak.onMissing(detections); } } } Iterator it = hashSet.iterator(); while (it.hasNext()) { this.zzba.delete(((Integer) it.next()).intValue()); } SparseArray detectedItems3 = detections.getDetectedItems(); for (int i3 = 0; i3 < detectedItems3.size(); i3++) { int keyAt3 = detectedItems3.keyAt(i3); T valueAt3 = detectedItems3.valueAt(i3); zza zzaVar2 = this.zzba.get(keyAt3); zza.zza(zzaVar2, 0); zzaVar2.zzak.onUpdate(detections, valueAt3); } } private MultiProcessor() { this.zzba = new SparseArray<>(); this.zzal = 3; } }