@Override protected String doBackward(T enumValue) { return enumValue.name(); }
@Override public String convert(Enum<?> source) { return source.name(); }
/** * {@inheritDoc} */ public String getValue() { return value.name(); }
/** * For the given Enum value {@code rank}, returns the value's {@code "EnumClass.name"}, which is * used in exception and warning output. */ private static String getLockName(Enum<?> rank) { return rank.getDeclaringClass().getSimpleName() + "." + rank.name(); }
private String convertToString (Enum e) { return enumNames ? e.name() : e.toString(); }
private String convertToString (Enum e) { return enumNames ? e.name() : e.toString(); }
public <N extends Enum<?>> String getTableName(N tableName) { return tableNamePrefix + tableName.name().toLowerCase() + tableNameSuffix; }
public <N extends Enum<?>> String getColumnName(N columnName) { return columnNamePrefix + columnName.name().toLowerCase() + columnNameSuffix; }
/** * For the given Enum value {@code rank}, returns the value's {@code "EnumClass.name"}, which is * used in exception and warning output. */ private static String getLockName(Enum<?> rank) { return rank.getDeclaringClass().getSimpleName() + "." + rank.name(); }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") public <T extends Enum<T>> T load(Class<T> type) { return value.getDeclaringClass() == type ? (T) value : Enum.valueOf(type, value.name()); } }
@GwtIncompatible // java.lang.ref.WeakReference private static <T extends Enum<T>> Map<String, WeakReference<? extends Enum<?>>> populateCache( Class<T> enumClass) { Map<String, WeakReference<? extends Enum<?>>> result = new HashMap<>(); for (T enumInstance : EnumSet.allOf(enumClass)) { result.put(enumInstance.name(), new WeakReference<Enum<?>>(enumInstance)); } enumConstantCache.put(enumClass, result); return result; }
/** * 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); } }
@GwtIncompatible // java.lang.ref.WeakReference private static <T extends Enum<T>> Map<String, WeakReference<? extends Enum<?>>> populateCache( Class<T> enumClass) { Map<String, WeakReference<? extends Enum<?>>> result = new HashMap<>(); for (T enumInstance : EnumSet.allOf(enumClass)) { result.put(enumInstance.name(), new WeakReference<Enum<?>>(enumInstance)); } enumConstantCache.put(enumClass, result); return result; }
protected void _reportFailedNullCoerce(DeserializationContext ctxt, boolean state, Enum<?> feature, String inputDesc) throws JsonMappingException { String enableDesc = state ? "enable" : "disable"; ctxt.reportInputMismatch(this, "Cannot coerce %s to Null value %s (%s `%s.%s` to allow)", inputDesc, _coercedTypeDesc(), enableDesc, feature.getClass().getSimpleName(), feature.name()); }
protected void _reportFailedNullCoerce(DeserializationContext ctxt, boolean state, Enum<?> feature, String inputDesc) throws JsonMappingException { String enableDesc = state ? "enable" : "disable"; ctxt.reportInputMismatch(this, "Cannot coerce %s to Null value %s (%s `%s.%s` to allow)", inputDesc, _coercedTypeDesc(), enableDesc, feature.getClass().getSimpleName(), feature.name()); }
public Node representData(Object data) { Tag tag = new Tag(data.getClass()); return representScalar(getTag(data.getClass(), tag), ((Enum<?>) data).name()); } }
private void writeObjectEntry(TagWriter tagWriter, @Nullable String valueProperty, @Nullable String labelProperty, Object item, int itemIndex) throws JspException { BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(item); Object renderValue; if (valueProperty != null) { renderValue = wrapper.getPropertyValue(valueProperty); } else if (item instanceof Enum) { renderValue = ((Enum<?>) item).name(); } else { renderValue = item; } Object renderLabel = (labelProperty != null ? wrapper.getPropertyValue(labelProperty) : item); writeElementTag(tagWriter, item, renderValue, renderLabel, itemIndex); }
@SuppressWarnings("unchecked") public static <E extends Enum<E>> void checkEnum(Class<E> enumClass) { try { Method m = enumClass.getMethod("values"); m.setAccessible(true); Method e = enumClass.getMethod("valueOf", String.class); m.setAccessible(true); for (Enum<E> o : (Enum<E>[])m.invoke(null)) { assertSame(o, e.invoke(null, o.name())); } } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } }
@SuppressWarnings("unchecked") @Test public void hashSetCallableEnum() { // inlined TestHelper.checkEnum due to access restrictions try { Method m = Functions.HashSetCallable.class.getMethod("values"); m.setAccessible(true); Method e = Functions.HashSetCallable.class.getMethod("valueOf", String.class); e.setAccessible(true); for (Enum<HashSetCallable> o : (Enum<HashSetCallable>[])m.invoke(null)) { assertSame(o, e.invoke(null, o.name())); } } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } }
@SuppressWarnings("unchecked") @Test public void naturalComparatorEnum() { // inlined TestHelper.checkEnum due to access restrictions try { Method m = Functions.NaturalComparator.class.getMethod("values"); m.setAccessible(true); Method e = Functions.NaturalComparator.class.getMethod("valueOf", String.class); e.setAccessible(true); for (Enum<NaturalComparator> o : (Enum<NaturalComparator>[])m.invoke(null)) { assertSame(o, e.invoke(null, o.name())); } } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } }