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; /* 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 */ 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 final 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 final String doBackward(T t) { return t.name(); } @Override // com.google.common.base.Converter, com.google.common.base.Function public final boolean equals(Object obj) { if (obj instanceof StringConverter) { return this.enumClass.equals(((StringConverter) obj).enumClass); } return false; } public final int hashCode() { return this.enumClass.hashCode(); } public final String toString() { String name = this.enumClass.getName(); StringBuilder sb = new StringBuilder(String.valueOf(name).length() + 29); sb.append("Enums.stringConverter("); sb.append(name); sb.append(".class)"); return sb.toString(); } } }