package coil.request;

import K4.a;
import coil.util.Collections;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import kotlin.jvm.internal.h;
import kotlin.jvm.internal.o;
import w4.k;
import x4.AbstractC3229F;
import x4.z;

/* JADX INFO: loaded from: classes.dex */
public final class Parameters implements Iterable<k>, a {
    public static final Companion Companion = new Companion(null);
    public static final Parameters EMPTY = new Parameters();
    private final Map<String, Entry> entries;

    public static final class Builder {
        private final Map<String, Entry> entries;

        public Builder() {
            this.entries = new LinkedHashMap();
        }

        public static /* synthetic */ Builder set$default(Builder builder, String str, Object obj, String str2, int i6, Object obj2) {
            if ((i6 & 4) != 0) {
                str2 = obj != null ? obj.toString() : null;
            }
            return builder.set(str, obj, str2);
        }

        public final Parameters build() {
            return new Parameters(Collections.toImmutableMap(this.entries), null);
        }

        public final Builder remove(String str) {
            this.entries.remove(str);
            return this;
        }

        public final Builder set(String str, Object obj) {
            return set$default(this, str, obj, null, 4, null);
        }

        public final Builder set(String str, Object obj, String str2) {
            this.entries.put(str, new Entry(obj, str2));
            return this;
        }

        public Builder(Parameters parameters) {
            this.entries = AbstractC3229F.I(parameters.entries);
        }
    }

    public static final class Companion {
        public /* synthetic */ Companion(h hVar) {
            this();
        }

        private Companion() {
        }
    }

    public static final class Entry {
        private final String memoryCacheKey;
        private final Object value;

        public Entry(Object obj, String str) {
            this.value = obj;
            this.memoryCacheKey = str;
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof Entry)) {
                return false;
            }
            Entry entry = (Entry) obj;
            return o.c(this.value, entry.value) && o.c(this.memoryCacheKey, entry.memoryCacheKey);
        }

        public final String getMemoryCacheKey() {
            return this.memoryCacheKey;
        }

        public final Object getValue() {
            return this.value;
        }

        public int hashCode() {
            Object obj = this.value;
            int iHashCode = (obj != null ? obj.hashCode() : 0) * 31;
            String str = this.memoryCacheKey;
            return iHashCode + (str != null ? str.hashCode() : 0);
        }

        public String toString() {
            StringBuilder sb = new StringBuilder("Entry(value=");
            sb.append(this.value);
            sb.append(", memoryCacheKey=");
            return Z0.o.r(sb, this.memoryCacheKey, ')');
        }
    }

    public /* synthetic */ Parameters(Map map, h hVar) {
        this(map);
    }

    public final Entry entry(String str) {
        return this.entries.get(str);
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        return (obj instanceof Parameters) && o.c(this.entries, ((Parameters) obj).entries);
    }

    public int hashCode() {
        return this.entries.hashCode();
    }

    public final boolean isEmpty() {
        return this.entries.isEmpty();
    }

    @Override // java.lang.Iterable
    public Iterator<k> iterator() {
        Map<String, Entry> map = this.entries;
        ArrayList arrayList = new ArrayList(map.size());
        for (Map.Entry<String, Entry> entry : map.entrySet()) {
            arrayList.add(new k(entry.getKey(), entry.getValue()));
        }
        return arrayList.iterator();
    }

    public final String memoryCacheKey(String str) {
        Entry entry = this.entries.get(str);
        if (entry != null) {
            return entry.getMemoryCacheKey();
        }
        return null;
    }

    public final Map<String, String> memoryCacheKeys() {
        if (isEmpty()) {
            return z.f26066a;
        }
        Map<String, Entry> map = this.entries;
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        for (Map.Entry<String, Entry> entry : map.entrySet()) {
            String memoryCacheKey = entry.getValue().getMemoryCacheKey();
            if (memoryCacheKey != null) {
                linkedHashMap.put(entry.getKey(), memoryCacheKey);
            }
        }
        return linkedHashMap;
    }

    public final Builder newBuilder() {
        return new Builder(this);
    }

    public final int size() {
        return this.entries.size();
    }

    public String toString() {
        return "Parameters(entries=" + this.entries + ')';
    }

    public final <T> T value(String str) {
        Entry entry = this.entries.get(str);
        if (entry != null) {
            return (T) entry.getValue();
        }
        return null;
    }

    public final Map<String, Object> values() {
        if (isEmpty()) {
            return z.f26066a;
        }
        Map<String, Entry> map = this.entries;
        LinkedHashMap linkedHashMap = new LinkedHashMap(AbstractC3229F.u(map.size()));
        Iterator<T> it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            linkedHashMap.put(entry.getKey(), ((Entry) entry.getValue()).getValue());
        }
        return linkedHashMap;
    }

    private Parameters(Map<String, Entry> map) {
        this.entries = map;
    }

    public Parameters() {
        this(z.f26066a);
    }
}
