94 lines
3.1 KiB
Java
94 lines
3.1 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;
|
||
|
|
||
|
/* loaded from: classes2.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 final 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(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 final UnmodifiableIterator<K> keyIterator() {
|
||
|
return Iterators.unmodifiableIterator(this.delegate.keySet().iterator());
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Map
|
||
|
public final int size() {
|
||
|
return this.delegate.size();
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.collect.ImmutableMap, java.util.Map
|
||
|
public final boolean containsKey(Object obj) {
|
||
|
return this.delegate.containsKey(obj);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.collect.ImmutableMap, java.util.Map
|
||
|
public final V get(Object obj) {
|
||
|
return this.delegate.get(obj);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.collect.ImmutableMap, java.util.Map
|
||
|
public final boolean equals(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
|
||
|
final UnmodifiableIterator<Map.Entry<K, V>> entryIterator() {
|
||
|
return Maps.unmodifiableEntryIterator(this.delegate.entrySet().iterator());
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.collect.ImmutableMap
|
||
|
final Object writeReplace() {
|
||
|
return new EnumSerializedForm(this.delegate);
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|