package com.google.protobuf; import com.google.protobuf.Internal; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; /* loaded from: classes3.dex */ public final class MapFieldLite extends LinkedHashMap { private static final MapFieldLite EMPTY_MAP_FIELD; private boolean isMutable; public static MapFieldLite emptyMapField() { return (MapFieldLite) EMPTY_MAP_FIELD; } public boolean isMutable() { return this.isMutable; } public void makeImmutable() { this.isMutable = false; } private MapFieldLite() { this.isMutable = true; } private MapFieldLite(Map map) { super(map); this.isMutable = true; } static { MapFieldLite mapFieldLite = new MapFieldLite<>(); EMPTY_MAP_FIELD = mapFieldLite; mapFieldLite.makeImmutable(); } public void mergeFrom(MapFieldLite mapFieldLite) { ensureMutable(); if (mapFieldLite.isEmpty()) { return; } putAll(mapFieldLite); } @Override // java.util.LinkedHashMap, java.util.HashMap, java.util.AbstractMap, java.util.Map public Set> entrySet() { return isEmpty() ? Collections.emptySet() : super.entrySet(); } @Override // java.util.LinkedHashMap, java.util.HashMap, java.util.AbstractMap, java.util.Map public void clear() { ensureMutable(); super.clear(); } @Override // java.util.HashMap, java.util.AbstractMap, java.util.Map public V put(K k, V v) { ensureMutable(); Internal.checkNotNull(k); Internal.checkNotNull(v); return (V) super.put(k, v); } public V put(Map.Entry entry) { return put(entry.getKey(), entry.getValue()); } @Override // java.util.HashMap, java.util.AbstractMap, java.util.Map public void putAll(Map map) { ensureMutable(); checkForNullKeysAndValues(map); super.putAll(map); } @Override // java.util.HashMap, java.util.AbstractMap, java.util.Map public V remove(Object obj) { ensureMutable(); return (V) super.remove(obj); } private static void checkForNullKeysAndValues(Map map) { for (Object obj : map.keySet()) { Internal.checkNotNull(obj); Internal.checkNotNull(map.get(obj)); } } private static boolean equals(Object obj, Object obj2) { if ((obj instanceof byte[]) && (obj2 instanceof byte[])) { return Arrays.equals((byte[]) obj, (byte[]) obj2); } return obj.equals(obj2); } public static boolean equals(Map map, Map map2) { if (map == map2) { return true; } if (map.size() != map2.size()) { return false; } for (Map.Entry entry : map.entrySet()) { if (!map2.containsKey(entry.getKey()) || !equals(entry.getValue(), map2.get(entry.getKey()))) { return false; } } return true; } @Override // java.util.AbstractMap, java.util.Map public boolean equals(Object obj) { return (obj instanceof Map) && equals((Map) this, (Map) obj); } private static int calculateHashCodeForObject(Object obj) { if (obj instanceof byte[]) { return Internal.hashCode((byte[]) obj); } if (obj instanceof Internal.EnumLite) { throw new UnsupportedOperationException(); } return obj.hashCode(); } public static int calculateHashCodeForMap(Map map) { int i = 0; for (Map.Entry entry : map.entrySet()) { i += calculateHashCodeForObject(entry.getValue()) ^ calculateHashCodeForObject(entry.getKey()); } return i; } @Override // java.util.AbstractMap, java.util.Map public int hashCode() { return calculateHashCodeForMap(this); } private static Object copy(Object obj) { if (!(obj instanceof byte[])) { return obj; } byte[] bArr = (byte[]) obj; return Arrays.copyOf(bArr, bArr.length); } /* JADX WARN: Multi-variable type inference failed */ public static Map copy(Map map) { LinkedHashMap linkedHashMap = new LinkedHashMap(); for (Map.Entry entry : map.entrySet()) { linkedHashMap.put(entry.getKey(), copy(entry.getValue())); } return linkedHashMap; } public MapFieldLite mutableCopy() { return isEmpty() ? new MapFieldLite<>() : new MapFieldLite<>(this); } private void ensureMutable() { if (!isMutable()) { throw new UnsupportedOperationException(); } } }