package com.google.common.collect; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.primitives.Primitives; import java.io.Serializable; import java.util.Map; /* loaded from: classes2.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(Class cls, T t) { return new ImmutableClassToInstanceMap<>(ImmutableMap.of(cls, t)); } public static Builder builder() { return new Builder<>(); } /* loaded from: classes2.dex */ public static final class Builder { private final ImmutableMap.Builder, B> mapBuilder = ImmutableMap.builder(); public final Builder put(Class cls, T t) { this.mapBuilder.put(cls, t); return this; } public final 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 final ImmutableClassToInstanceMap build() { ImmutableMap, B> build = this.mapBuilder.build(); if (build.isEmpty()) { return ImmutableClassToInstanceMap.of(); } return new ImmutableClassToInstanceMap<>(build); } } 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 public final T getInstance(Class cls) { return this.delegate.get(Preconditions.checkNotNull(cls)); } @Override // com.google.common.collect.ClassToInstanceMap @Deprecated public final T putInstance(Class cls, T t) { throw new UnsupportedOperationException(); } final Object readResolve() { return isEmpty() ? of() : this; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.ForwardingMap, com.google.common.collect.ForwardingObject public final Map, B> delegate() { return this.delegate; } public static ImmutableClassToInstanceMap of() { return (ImmutableClassToInstanceMap) EMPTY; } }