package com.google.common.base; import java.io.Serializable; import java.lang.ref.WeakReference; import java.lang.reflect.Field; import java.util.EnumSet; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.WeakHashMap; import javax.annotation.CheckForNull; @ElementTypesAreNonnullByDefault /* loaded from: classes2.dex */ public final class Enums { private static final Map>, Map>>> enumConstantCache = new WeakHashMap(); private Enums() { } public static Field getField(Enum r1) { try { return r1.getDeclaringClass().getDeclaredField(r1.name()); } catch (NoSuchFieldException e) { throw new AssertionError(e); } } public static > Optional getIfPresent(Class cls, String str) { Preconditions.checkNotNull(cls); Preconditions.checkNotNull(str); return Platform.getEnumIfPresent(cls, str); } private static > Map>> populateCache(Class cls) { HashMap hashMap = new HashMap(); Iterator it = EnumSet.allOf(cls).iterator(); while (it.hasNext()) { Enum r2 = (Enum) it.next(); hashMap.put(r2.name(), new WeakReference(r2)); } enumConstantCache.put(cls, hashMap); return hashMap; } /* JADX INFO: Access modifiers changed from: package-private */ public static > Map>> getEnumConstants(Class cls) { Map>> map; Map>, Map>>> map2 = enumConstantCache; synchronized (map2) { map = map2.get(cls); if (map == null) { map = populateCache(cls); } } return map; } public static > Converter stringConverter(Class cls) { return new StringConverter(cls); } /* loaded from: classes2.dex */ private static final class StringConverter> extends Converter implements Serializable { private static final long serialVersionUID = 0; private final Class enumClass; StringConverter(Class cls) { this.enumClass = (Class) Preconditions.checkNotNull(cls); } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.base.Converter public T doForward(String str) { return (T) Enum.valueOf(this.enumClass, str); } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.base.Converter public String doBackward(T t) { return t.name(); } @Override // com.google.common.base.Converter, com.google.common.base.Function public boolean equals(@CheckForNull Object obj) { if (obj instanceof StringConverter) { return this.enumClass.equals(((StringConverter) obj).enumClass); } return false; } public int hashCode() { return this.enumClass.hashCode(); } public String toString() { String name = this.enumClass.getName(); return new StringBuilder(String.valueOf(name).length() + 29).append("Enums.stringConverter(").append(name).append(".class)").toString(); } } }