package com.google.common.collect; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.primitives.Primitives; import com.google.errorprone.annotations.Immutable; import java.io.Serializable; import java.util.Map; import javax.annotation.CheckForNull; @Immutable(containerOf = {"B"}) @ElementTypesAreNonnullByDefault /* loaded from: classes3.dex */ public final class ImmutableClassToInstanceMap extends ForwardingMap, B> implements ClassToInstanceMap, Serializable { private static final ImmutableClassToInstanceMap EMPTY = new ImmutableClassToInstanceMap<>(ImmutableMap.of()); private final ImmutableMap, B> delegate; public static ImmutableClassToInstanceMap of() { return (ImmutableClassToInstanceMap) EMPTY; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.ForwardingMap, com.google.common.collect.ForwardingObject public Map, B> delegate() { return this.delegate; } public static ImmutableClassToInstanceMap of(Class cls, T t) { return new ImmutableClassToInstanceMap<>(ImmutableMap.of(cls, t)); } public static Builder builder() { return new Builder<>(); } /* loaded from: classes3.dex */ public static final class Builder { private final ImmutableMap.Builder, B> mapBuilder = ImmutableMap.builder(); public Builder put(Class cls, T t) { this.mapBuilder.put(cls, t); return this; } public Builder putAll(Map, ? extends T> map) { for (Map.Entry, ? extends T> entry : map.entrySet()) { Class key = entry.getKey(); this.mapBuilder.put(key, cast(key, entry.getValue())); } return this; } private static T cast(Class cls, B b) { return (T) Primitives.wrap(cls).cast(b); } public ImmutableClassToInstanceMap build() { ImmutableMap, B> buildOrThrow = this.mapBuilder.buildOrThrow(); if (buildOrThrow.isEmpty()) { return ImmutableClassToInstanceMap.of(); } return new ImmutableClassToInstanceMap<>(buildOrThrow); } } public static ImmutableClassToInstanceMap copyOf(Map, ? extends S> map) { if (map instanceof ImmutableClassToInstanceMap) { return (ImmutableClassToInstanceMap) map; } return new Builder().putAll(map).build(); } private ImmutableClassToInstanceMap(ImmutableMap, B> immutableMap) { this.delegate = immutableMap; } @Override // com.google.common.collect.ClassToInstanceMap @CheckForNull public T getInstance(Class cls) { return this.delegate.get(Preconditions.checkNotNull(cls)); } @Override // com.google.common.collect.ClassToInstanceMap @CheckForNull @Deprecated public T putInstance(Class cls, T t) { throw new UnsupportedOperationException(); } Object readResolve() { return isEmpty() ? of() : this; } }