Rabbit-R1/switch port/java/sources/com/google/common/collect/ImmutableEnumMap.java
2024-05-21 17:08:36 -04:00

96 lines
3.2 KiB
Java

package com.google.common.collect;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.io.Serializable;
import java.lang.Enum;
import java.util.EnumMap;
import java.util.Map;
import javax.annotation.CheckForNull;
@ElementTypesAreNonnullByDefault
/* loaded from: classes3.dex */
final class ImmutableEnumMap<K extends Enum<K>, V> extends ImmutableMap.IteratorBasedImmutableMap<K, V> {
private final transient EnumMap<K, V> delegate;
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ImmutableMap
public boolean isPartialView() {
return false;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static <K extends Enum<K>, V> ImmutableMap<K, V> asImmutable(EnumMap<K, V> enumMap) {
int size = enumMap.size();
if (size == 0) {
return ImmutableMap.of();
}
if (size == 1) {
Map.Entry entry = (Map.Entry) Iterables.getOnlyElement(enumMap.entrySet());
return ImmutableMap.of((Enum) entry.getKey(), entry.getValue());
}
return new ImmutableEnumMap(enumMap);
}
private ImmutableEnumMap(EnumMap<K, V> enumMap) {
this.delegate = enumMap;
Preconditions.checkArgument(!enumMap.isEmpty());
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ImmutableMap
public UnmodifiableIterator<K> keyIterator() {
return Iterators.unmodifiableIterator(this.delegate.keySet().iterator());
}
@Override // java.util.Map
public int size() {
return this.delegate.size();
}
@Override // com.google.common.collect.ImmutableMap, java.util.Map
public boolean containsKey(@CheckForNull Object obj) {
return this.delegate.containsKey(obj);
}
@Override // com.google.common.collect.ImmutableMap, java.util.Map
@CheckForNull
public V get(@CheckForNull Object obj) {
return this.delegate.get(obj);
}
@Override // com.google.common.collect.ImmutableMap, java.util.Map
public boolean equals(@CheckForNull Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof ImmutableEnumMap) {
obj = ((ImmutableEnumMap) obj).delegate;
}
return this.delegate.equals(obj);
}
@Override // com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap
UnmodifiableIterator<Map.Entry<K, V>> entryIterator() {
return Maps.unmodifiableEntryIterator(this.delegate.entrySet().iterator());
}
@Override // com.google.common.collect.ImmutableMap
Object writeReplace() {
return new EnumSerializedForm(this.delegate);
}
/* loaded from: classes3.dex */
private static class EnumSerializedForm<K extends Enum<K>, V> implements Serializable {
private static final long serialVersionUID = 0;
final EnumMap<K, V> delegate;
EnumSerializedForm(EnumMap<K, V> enumMap) {
this.delegate = enumMap;
}
Object readResolve() {
return new ImmutableEnumMap(this.delegate);
}
}
}