|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.common.base.Enums
@GwtCompatible(emulated=true) @Beta public final class Enums
Utility methods for working with Enum
instances.
Method Summary | ||
---|---|---|
static java.lang.reflect.Field |
getField(java.lang.Enum<?> enumValue)
Returns the Field in which enumValue is defined. |
|
static
|
getIfPresent(java.lang.Class<T> enumClass,
java.lang.String value)
Returns an optional enum constant for the given type, using Enum.valueOf(java.lang.Class . |
|
static
|
valueOfFunction(java.lang.Class<T> enumClass)
Returns a Function that maps an Enum name to the associated
Enum constant. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
@GwtIncompatible(value="reflection") public static java.lang.reflect.Field getField(java.lang.Enum<?> enumValue)
Field
in which enumValue
is defined.
For example, to get the Description
annotation on the GOLF
constant of enum Sport
, use
Enums.getField(Sport.GOLF).getAnnotation(Description.class)
.
public static <T extends java.lang.Enum<T>> Function<java.lang.String,T> valueOfFunction(java.lang.Class<T> enumClass)
Function
that maps an Enum
name to the associated
Enum
constant. The Function
will return null
if the
Enum
constant does not exist.
enumClass
- the Class
of the Enum
declaring the
constant values.public static <T extends java.lang.Enum<T>> Optional<T> getIfPresent(java.lang.Class<T> enumClass, java.lang.String value)
Enum.valueOf(java.lang.Class, java.lang.String)
. 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,
Enums.getIfPresent(Country.class, countryInput).or(Country.DEFAULT);
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |