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

118 lines
3.9 KiB
Java

package com.google.common.collect;
import com.google.errorprone.annotations.concurrent.LazyInit;
import java.io.Serializable;
import java.lang.Enum;
import java.util.Collection;
import java.util.EnumSet;
import javax.annotation.CheckForNull;
@ElementTypesAreNonnullByDefault
/* loaded from: classes3.dex */
final class ImmutableEnumSet<E extends Enum<E>> extends ImmutableSet<E> {
private final transient EnumSet<E> delegate;
@LazyInit
private transient int hashCode;
@Override // com.google.common.collect.ImmutableSet
boolean isHashCodeFast() {
return true;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ImmutableCollection
public boolean isPartialView() {
return false;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static ImmutableSet asImmutable(EnumSet enumSet) {
int size = enumSet.size();
if (size == 0) {
return ImmutableSet.of();
}
if (size == 1) {
return ImmutableSet.of(Iterables.getOnlyElement(enumSet));
}
return new ImmutableEnumSet(enumSet);
}
private ImmutableEnumSet(EnumSet<E> enumSet) {
this.delegate = enumSet;
}
@Override // com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet, com.google.common.collect.SortedIterable
public UnmodifiableIterator<E> iterator() {
return Iterators.unmodifiableIterator(this.delegate.iterator());
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public int size() {
return this.delegate.size();
}
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean contains(@CheckForNull Object obj) {
return this.delegate.contains(obj);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean containsAll(Collection<?> collection) {
if (collection instanceof ImmutableEnumSet) {
collection = ((ImmutableEnumSet) collection).delegate;
}
return this.delegate.containsAll(collection);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean isEmpty() {
return this.delegate.isEmpty();
}
@Override // com.google.common.collect.ImmutableSet, java.util.Collection, java.util.Set
public boolean equals(@CheckForNull Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof ImmutableEnumSet) {
obj = ((ImmutableEnumSet) obj).delegate;
}
return this.delegate.equals(obj);
}
@Override // com.google.common.collect.ImmutableSet, java.util.Collection, java.util.Set
public int hashCode() {
int i = this.hashCode;
if (i != 0) {
return i;
}
int hashCode = this.delegate.hashCode();
this.hashCode = hashCode;
return hashCode;
}
@Override // java.util.AbstractCollection
public String toString() {
return this.delegate.toString();
}
@Override // com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection
Object writeReplace() {
return new EnumSerializedForm(this.delegate);
}
/* loaded from: classes3.dex */
private static class EnumSerializedForm<E extends Enum<E>> implements Serializable {
private static final long serialVersionUID = 0;
final EnumSet<E> delegate;
EnumSerializedForm(EnumSet<E> enumSet) {
this.delegate = enumSet;
}
Object readResolve() {
return new ImmutableEnumSet(this.delegate.clone());
}
}
}