package androidx.work.impl;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.work.ExistingWorkPolicy;
import androidx.work.f0;
import androidx.work.i0;
import androidx.work.u;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public final class g extends f0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final o f4599a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f4600b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final ExistingWorkPolicy f4601c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final List f4602d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final ArrayList f4603e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final ArrayList f4604f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final List f4605g;

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

    static {
        u.e("WorkContinuationImpl");
    }

    public g(@NonNull o oVar, @Nullable String str, @NonNull ExistingWorkPolicy existingWorkPolicy, @NonNull List<? extends i0> list, @Nullable List<g> list2) {
        this.f4599a = oVar;
        this.f4600b = str;
        this.f4601c = existingWorkPolicy;
        this.f4602d = list;
        this.f4605g = list2;
        this.f4603e = new ArrayList(list.size());
        this.f4604f = new ArrayList();
        if (list2 != null) {
            Iterator<g> it = list2.iterator();
            while (it.hasNext()) {
                this.f4604f.addAll(it.next().f4604f);
            }
        }
        for (int i10 = 0; i10 < list.size(); i10++) {
            String string = list.get(i10).f4566a.toString();
            this.f4603e.add(string);
            this.f4604f.add(string);
        }
    }

    public static boolean a(g gVar, HashSet hashSet) {
        hashSet.addAll(gVar.f4603e);
        HashSet hashSetB = b(gVar);
        Iterator it = hashSet.iterator();
        while (it.hasNext()) {
            if (hashSetB.contains((String) it.next())) {
                return true;
            }
        }
        List list = gVar.f4605g;
        if (list != null && !list.isEmpty()) {
            Iterator it2 = list.iterator();
            while (it2.hasNext()) {
                if (a((g) it2.next(), hashSet)) {
                    return true;
                }
            }
        }
        hashSet.removeAll(gVar.f4603e);
        return false;
    }

    public static HashSet b(g gVar) {
        HashSet hashSet = new HashSet();
        List list = gVar.f4605g;
        if (list != null && !list.isEmpty()) {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                hashSet.addAll(((g) it.next()).f4603e);
            }
        }
        return hashSet;
    }

    @Nullable
    public String getName() {
        return this.f4600b;
    }

    public g(@NonNull o oVar, @Nullable String str, @NonNull ExistingWorkPolicy existingWorkPolicy, @NonNull List<? extends i0> list) {
        this(oVar, str, existingWorkPolicy, list, null);
    }
}
