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

Method getIfPresent

corpus/java/training/guava/base/Enums.java:71–75  ·  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

69 * @since 12.0
70 */
71 public static <T extends Enum<T>> Optional<T> getIfPresent(Class<T> enumClass, String value) {
72 checkNotNull(enumClass);
73 checkNotNull(value);
74 return Platform.getEnumIfPresent(enumClass, value);
75 }
76
77 @GwtIncompatible // java.lang.ref.WeakReference
78 private static final Map<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