MCPcopy Create free account
hub / github.com/antlr/codebuff / getIfPresent

Method getIfPresent

output/java_guava/1.4.16/Enums.java:72–76  ·  view source on GitHub ↗

Returns an optional enum constant for the given type, using Enum#valueOf. If the constant does not exist, Optional#absent is returned. A common use case is for parsing user input or falling back to a default enum constant. For example, {@code Enums.getIfPresent(Country.class, country

(Class<T> enumClass, String value)

Source from the content-addressed store, hash-verified

70
71
72 public static <T extends Enum<T>> Optional<T> getIfPresent(Class<T> enumClass, String value) {
73 checkNotNull(enumClass);
74 checkNotNull(value);
75 return Platform.getEnumIfPresent(enumClass, value);
76 }
77
78 @GwtIncompatible // java.lang.ref.WeakReference
79 private static final Map<Class<? extends Enum<?>>, Map<String, WeakReference<? extends Enum<?>>>> enumConstantCache = new WeakHashMap<Class<? extends Enum<?>>, Map<String, WeakReference<? extends Enum<?>>>>();

Callers

nothing calls this directly

Calls 2

getEnumIfPresentMethod · 0.95
checkNotNullMethod · 0.45

Tested by

no test coverage detected