diff options
Diffstat (limited to 'guava/src/com/google/common/base/Enums.java')
-rw-r--r-- | guava/src/com/google/common/base/Enums.java | 46 |
1 files changed, 4 insertions, 42 deletions
diff --git a/guava/src/com/google/common/base/Enums.java b/guava/src/com/google/common/base/Enums.java index 6105410..f98e164 100644 --- a/guava/src/com/google/common/base/Enums.java +++ b/guava/src/com/google/common/base/Enums.java @@ -20,10 +20,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.Beta; import com.google.common.annotations.GwtCompatible; -import com.google.common.annotations.GwtIncompatible; import java.io.Serializable; -import java.lang.reflect.Field; import javax.annotation.Nullable; @@ -34,31 +32,13 @@ import javax.annotation.Nullable; * * @since 9.0 */ -@GwtCompatible(emulated = true) +@GwtCompatible @Beta public final class Enums { private Enums() {} /** - * Returns the {@link Field} in which {@code enumValue} is defined. - * For example, to get the {@code Description} annotation on the {@code GOLF} - * constant of enum {@code Sport}, use - * {@code Enums.getField(Sport.GOLF).getAnnotation(Description.class)}. - * - * @since 12.0 - */ - @GwtIncompatible("reflection") - public static Field getField(Enum<?> enumValue) { - Class<?> clazz = enumValue.getDeclaringClass(); - try { - return clazz.getDeclaredField(enumValue.name()); - } catch (NoSuchFieldException impossible) { - throw new AssertionError(impossible); - } - } - - /** * Returns a {@link Function} that maps an {@link Enum} name to the associated * {@code Enum} constant. The {@code Function} will return {@code null} if the * {@code Enum} constant does not exist. @@ -71,11 +51,11 @@ public final class Enums { } /** - * A {@link Function} that maps an {@link Enum} name to the associated + * {@link Function} that maps an {@link Enum} name to the associated * constant, or {@code null} if the constant does not exist. */ - private static final class ValueOfFunction<T extends Enum<T>> - implements Function<String, T>, Serializable { + private static final class ValueOfFunction<T extends Enum<T>> implements + Function<String, T>, Serializable { private final Class<T> enumClass; @@ -107,22 +87,4 @@ public final class Enums { private static final long serialVersionUID = 0; } - - /** - * Returns an optional enum constant for the given type, using {@link Enum#valueOf}. If the - * constant does not exist, {@link 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, countryInput).or(Country.DEFAULT);} - * - * @since 12.0 - */ - public static <T extends Enum<T>> Optional<T> getIfPresent(Class<T> enumClass, String value) { - checkNotNull(enumClass); - checkNotNull(value); - try { - return Optional.of(Enum.valueOf(enumClass, value)); - } catch (IllegalArgumentException iae) { - return Optional.absent(); - } - } } |