package n5;

import android.text.TextUtils;
import androidx.slice.Slice;
import androidx.slice.SliceItem;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* loaded from: classes.dex */
public abstract class e {

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class a implements InterfaceC0677e {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ String f29810a;

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ String[] f29811b;

        /* renamed from: c, reason: collision with root package name */
        final /* synthetic */ String[] f29812c;

        a(String str, String[] strArr, String[] strArr2) {
            this.f29810a = str;
            this.f29811b = strArr;
            this.f29812c = strArr2;
        }

        @Override // n5.e.InterfaceC0677e
        /* renamed from: b, reason: merged with bridge method [inline-methods] */
        public boolean a(SliceItem sliceItem) {
            return e.a(sliceItem, this.f29810a) && e.j(sliceItem, this.f29811b) && !e.i(sliceItem, this.f29812c);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class b implements InterfaceC0677e {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ String f29813a;

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ String[] f29814b;

        /* renamed from: c, reason: collision with root package name */
        final /* synthetic */ String[] f29815c;

        b(String str, String[] strArr, String[] strArr2) {
            this.f29813a = str;
            this.f29814b = strArr;
            this.f29815c = strArr2;
        }

        @Override // n5.e.InterfaceC0677e
        /* renamed from: b, reason: merged with bridge method [inline-methods] */
        public boolean a(SliceItem sliceItem) {
            return e.a(sliceItem, this.f29813a) && e.j(sliceItem, this.f29814b) && !e.i(sliceItem, this.f29815c);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class c implements Iterator {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ ArrayList f29816p;

        c(ArrayList arrayList) {
            this.f29816p = arrayList;
        }

        @Override // java.util.Iterator
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public SliceItem next() {
            SliceItem sliceItem = (SliceItem) this.f29816p.remove(0);
            if ("slice".equals(sliceItem.c()) || "action".equals(sliceItem.c())) {
                this.f29816p.addAll(sliceItem.i().c());
            }
            return sliceItem;
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            return this.f29816p.size() != 0;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class d implements Iterator {

        /* renamed from: p, reason: collision with root package name */
        Object f29817p = a();

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ Iterator f29818q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ InterfaceC0677e f29819r;

        d(Iterator it, InterfaceC0677e interfaceC0677e) {
            this.f29818q = it;
            this.f29819r = interfaceC0677e;
        }

        private Object a() {
            while (this.f29818q.hasNext()) {
                Object next = this.f29818q.next();
                if (this.f29819r.a(next)) {
                    return next;
                }
            }
            return null;
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            return this.f29817p != null;
        }

        @Override // java.util.Iterator
        public Object next() {
            Object obj = this.f29817p;
            this.f29817p = a();
            return obj;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* renamed from: n5.e$e, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public interface InterfaceC0677e {
        boolean a(Object obj);
    }

    static boolean a(SliceItem sliceItem, String str) {
        return str == null || str.equals(sliceItem.c());
    }

    private static List b(Iterator it) {
        ArrayList arrayList = new ArrayList();
        while (it.hasNext()) {
            arrayList.add(it.next());
        }
        return arrayList;
    }

    private static Iterator c(Iterator it, InterfaceC0677e interfaceC0677e) {
        return new d(it, interfaceC0677e);
    }

    public static SliceItem d(Slice slice, String str, String str2, String str3) {
        return e(slice, str, new String[]{str2}, new String[]{str3});
    }

    public static SliceItem e(Slice slice, String str, String[] strArr, String[] strArr2) {
        return (SliceItem) g(c(k(slice), new b(str, strArr, strArr2)), null);
    }

    public static List f(Slice slice, String str, String[] strArr, String[] strArr2) {
        return b(c(k(slice), new a(str, strArr, strArr2)));
    }

    private static Object g(Iterator it, Object obj) {
        while (it.hasNext()) {
            Object next = it.next();
            if (next != null) {
                return next;
            }
        }
        return obj;
    }

    private static Iterator h(ArrayList arrayList) {
        return new c(arrayList);
    }

    public static boolean i(SliceItem sliceItem, String... strArr) {
        if (strArr == null) {
            return false;
        }
        List d10 = sliceItem.d();
        for (String str : strArr) {
            if (d10.contains(str)) {
                return true;
            }
        }
        return false;
    }

    public static boolean j(SliceItem sliceItem, String... strArr) {
        if (strArr == null) {
            return true;
        }
        List d10 = sliceItem.d();
        for (String str : strArr) {
            if (!TextUtils.isEmpty(str) && !d10.contains(str)) {
                return false;
            }
        }
        return true;
    }

    public static Iterator k(Slice slice) {
        ArrayList arrayList = new ArrayList();
        if (slice != null) {
            arrayList.addAll(slice.c());
        }
        return h(arrayList);
    }
}
