package androidx.datastore.preferences.protobuf;

import java.util.Iterator;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public final class Y implements Iterator {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public int f8046q = -1;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public boolean f8047r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public Iterator f8048s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final /* synthetic */ W f8049t;

    public Y(W w4) {
        this.f8049t = w4;
    }

    public final Iterator a() {
        if (this.f8048s == null) {
            this.f8048s = this.f8049t.f8039r.entrySet().iterator();
        }
        return this.f8048s;
    }

    @Override // java.util.Iterator
    public final boolean hasNext() {
        int i = this.f8046q + 1;
        W w4 = this.f8049t;
        return i < w4.f8038q.size() || (!w4.f8039r.isEmpty() && a().hasNext());
    }

    @Override // java.util.Iterator
    public final Object next() {
        this.f8047r = true;
        int i = this.f8046q + 1;
        this.f8046q = i;
        W w4 = this.f8049t;
        return i < w4.f8038q.size() ? (Map.Entry) w4.f8038q.get(this.f8046q) : (Map.Entry) a().next();
    }

    @Override // java.util.Iterator
    public final void remove() {
        if (!this.f8047r) {
            throw new IllegalStateException("remove() was called before next()");
        }
        this.f8047r = false;
        int i = W.f8037v;
        W w4 = this.f8049t;
        w4.b();
        if (this.f8046q >= w4.f8038q.size()) {
            a().remove();
            return;
        }
        int i5 = this.f8046q;
        this.f8046q = i5 - 1;
        w4.h(i5);
    }
}
