本文整理了Java中java.lang.Enum.name()
方法的一些代码示例,展示了Enum.name()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Enum.name()
方法的具体详情如下:
包路径:java.lang.Enum
类名称:Enum
方法名:name
[英]The name of this enum constant, as declared in the enum declaration. Most programmers should use the #toString method rather than accessing this field.
[中]枚举声明中声明的此枚举常量的名称。大多数程序员应该使用#toString方法,而不是访问此字段。
代码示例来源:origin: google/guava
@Override
protected String doBackward(T enumValue) {
return enumValue.name();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public String convert(Enum<?> source) {
return source.name();
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public String getValue() {
return value.name();
}
代码示例来源:origin: google/guava
/**
* 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();
}
代码示例来源:origin: libgdx/libgdx
private String convertToString (Enum e) {
return enumNames ? e.name() : e.toString();
}
代码示例来源:origin: libgdx/libgdx
private String convertToString (Enum e) {
return enumNames ? e.name() : e.toString();
}
代码示例来源:origin: ch.qos.logback/logback-classic
public <N extends Enum<?>> String getTableName(N tableName) {
return tableNamePrefix + tableName.name().toLowerCase() + tableNameSuffix;
}
代码示例来源:origin: ch.qos.logback/logback-classic
public <N extends Enum<?>> String getColumnName(N columnName) {
return columnNamePrefix + columnName.name().toLowerCase() + columnNameSuffix;
}
代码示例来源:origin: prestodb/presto
/**
* 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();
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public <T extends Enum<T>> T load(Class<T> type) {
return value.getDeclaringClass() == type
? (T) value
: Enum.valueOf(type, value.name());
}
}
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: google/guava
/**
* 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);
}
}
代码示例来源:origin: prestodb/presto
@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;
}
代码示例来源:origin: prestodb/presto
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());
}
代码示例来源:origin: redisson/redisson
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());
}
代码示例来源:origin: redisson/redisson
public Node representData(Object data) {
Tag tag = new Tag(data.getClass());
return representScalar(getTag(data.getClass(), tag), ((Enum<?>) data).name());
}
}
代码示例来源:origin: spring-projects/spring-framework
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);
}
代码示例来源:origin: ReactiveX/RxJava
@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);
}
}
代码示例来源:origin: ReactiveX/RxJava
@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);
}
}
代码示例来源:origin: ReactiveX/RxJava
@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);
}
}
内容来源于网络,如有侵权,请联系作者删除!