package coil.memory;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import coil.memory.MemoryCache;
import coil.util.Utils;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import kotlin.jvm.internal.h;
import kotlin.jvm.internal.o;
import x4.z;

/* JADX INFO: loaded from: classes.dex */
public interface MemoryCache {

    public static final class Builder {
        private final Context context;
        private int maxSizeBytes;
        private double maxSizePercent;
        private boolean strongReferencesEnabled = true;
        private boolean weakReferencesEnabled = true;

        public Builder(Context context) {
            this.context = context;
            this.maxSizePercent = Utils.defaultMemoryCacheSizePercent(context);
        }

        public final MemoryCache build() {
            StrongMemoryCache emptyStrongMemoryCache;
            WeakMemoryCache realWeakMemoryCache = this.weakReferencesEnabled ? new RealWeakMemoryCache() : new EmptyWeakMemoryCache();
            if (this.strongReferencesEnabled) {
                double d6 = this.maxSizePercent;
                int iCalculateMemoryCacheSize = d6 > 0.0d ? Utils.calculateMemoryCacheSize(this.context, d6) : this.maxSizeBytes;
                emptyStrongMemoryCache = iCalculateMemoryCacheSize > 0 ? new RealStrongMemoryCache(iCalculateMemoryCacheSize, realWeakMemoryCache) : new EmptyStrongMemoryCache(realWeakMemoryCache);
            } else {
                emptyStrongMemoryCache = new EmptyStrongMemoryCache(realWeakMemoryCache);
            }
            return new RealMemoryCache(emptyStrongMemoryCache, realWeakMemoryCache);
        }

        public final Builder maxSizeBytes(int i6) {
            if (i6 < 0) {
                throw new IllegalArgumentException("size must be >= 0.");
            }
            this.maxSizePercent = 0.0d;
            this.maxSizeBytes = i6;
            return this;
        }

        public final Builder maxSizePercent(double d6) {
            if (0.0d > d6 || d6 > 1.0d) {
                throw new IllegalArgumentException("size must be in the range [0.0, 1.0].");
            }
            this.maxSizeBytes = 0;
            this.maxSizePercent = d6;
            return this;
        }

        public final Builder strongReferencesEnabled(boolean z6) {
            this.strongReferencesEnabled = z6;
            return this;
        }

        public final Builder weakReferencesEnabled(boolean z6) {
            this.weakReferencesEnabled = z6;
            return this;
        }
    }

    void clear();

    Value get(Key key);

    Set<Key> getKeys();

    int getMaxSize();

    int getSize();

    boolean remove(Key key);

    void set(Key key, Value value);

    void trimMemory(int i6);

    public static final class Key implements Parcelable {
        private final Map<String, String> extras;
        private final String key;
        private static final Companion Companion = new Companion(null);

        @Deprecated
        public static final Parcelable.Creator<Key> CREATOR = new Parcelable.Creator<Key>() { // from class: coil.memory.MemoryCache$Key$Companion$CREATOR$1
            /* JADX WARN: Can't rename method to resolve collision */
            @Override // android.os.Parcelable.Creator
            public MemoryCache.Key createFromParcel(Parcel parcel) {
                String string = parcel.readString();
                o.e(string);
                int i6 = parcel.readInt();
                LinkedHashMap linkedHashMap = new LinkedHashMap(i6);
                for (int i7 = 0; i7 < i6; i7++) {
                    String string2 = parcel.readString();
                    o.e(string2);
                    String string3 = parcel.readString();
                    o.e(string3);
                    linkedHashMap.put(string2, string3);
                }
                return new MemoryCache.Key(string, linkedHashMap);
            }

            /* JADX WARN: Can't rename method to resolve collision */
            @Override // android.os.Parcelable.Creator
            public MemoryCache.Key[] newArray(int i6) {
                return new MemoryCache.Key[i6];
            }
        };

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

            private Companion() {
            }
        }

        public Key(String str, Map<String, String> map) {
            this.key = str;
            this.extras = map;
        }

        /* JADX WARN: Multi-variable type inference failed */
        public static /* synthetic */ Key copy$default(Key key, String str, Map map, int i6, Object obj) {
            if ((i6 & 1) != 0) {
                str = key.key;
            }
            if ((i6 & 2) != 0) {
                map = key.extras;
            }
            return key.copy(str, map);
        }

        public final Key copy(String str, Map<String, String> map) {
            return new Key(str, map);
        }

        @Override // android.os.Parcelable
        public int describeContents() {
            return 0;
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof Key)) {
                return false;
            }
            Key key = (Key) obj;
            return o.c(this.key, key.key) && o.c(this.extras, key.extras);
        }

        public final Map<String, String> getExtras() {
            return this.extras;
        }

        public final String getKey() {
            return this.key;
        }

        public int hashCode() {
            return this.extras.hashCode() + (this.key.hashCode() * 31);
        }

        public String toString() {
            return "Key(key=" + this.key + ", extras=" + this.extras + ')';
        }

        @Override // android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i6) {
            parcel.writeString(this.key);
            parcel.writeInt(this.extras.size());
            for (Map.Entry<String, String> entry : this.extras.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                parcel.writeString(key);
                parcel.writeString(value);
            }
        }

        public /* synthetic */ Key(String str, Map map, int i6, h hVar) {
            this(str, (i6 & 2) != 0 ? z.f26066a : map);
        }
    }

    public static final class Value {
        private final Bitmap bitmap;
        private final Map<String, Object> extras;

        public Value(Bitmap bitmap, Map<String, ? extends Object> map) {
            this.bitmap = bitmap;
            this.extras = map;
        }

        /* JADX WARN: Multi-variable type inference failed */
        public static /* synthetic */ Value copy$default(Value value, Bitmap bitmap, Map map, int i6, Object obj) {
            if ((i6 & 1) != 0) {
                bitmap = value.bitmap;
            }
            if ((i6 & 2) != 0) {
                map = value.extras;
            }
            return value.copy(bitmap, map);
        }

        public final Value copy(Bitmap bitmap, Map<String, ? extends Object> map) {
            return new Value(bitmap, map);
        }

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

        public final Bitmap getBitmap() {
            return this.bitmap;
        }

        public final Map<String, Object> getExtras() {
            return this.extras;
        }

        public int hashCode() {
            return this.extras.hashCode() + (this.bitmap.hashCode() * 31);
        }

        public String toString() {
            return "Value(bitmap=" + this.bitmap + ", extras=" + this.extras + ')';
        }

        public /* synthetic */ Value(Bitmap bitmap, Map map, int i6, h hVar) {
            this(bitmap, (i6 & 2) != 0 ? z.f26066a : map);
        }
    }
}
