本文整理了Java中java.lang.Enum.toString()
方法的一些代码示例,展示了Enum.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Enum.toString()
方法的具体详情如下:
包路径:java.lang.Enum
类名称:Enum
方法名:toString
[英]Returns a string containing a concise, human-readable description of this object. In this case, the enum constant's name is returned.
[中]返回一个字符串,其中包含此对象的简明易读描述。在本例中,将返回枚举常量的名称。
代码示例来源:origin: redisson/redisson
@Override
public String toString() {
return enumeration.toString();
}
}
代码示例来源:origin: pxb1988/dex2jar
@Override
public String toString() {
return name == null ? super.toString() : name;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Check whether the given array of enum constants contains a constant with the given name.
* @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()}
* @param constant the constant name to find (must not be null or empty string)
* @param caseSensitive whether case is significant in determining a match
* @return whether the constant has been found in the given array
*/
public static boolean containsConstant(Enum<?>[] enumValues, String constant, boolean caseSensitive) {
for (Enum<?> candidate : enumValues) {
if (caseSensitive ? candidate.toString().equals(constant) :
candidate.toString().equalsIgnoreCase(constant)) {
return true;
}
}
return false;
}
代码示例来源:origin: Tencent/tinker
@Override
public String toString() {
return super.toString().toLowerCase();
}
}
代码示例来源: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 tableName.toString().toLowerCase();
}
代码示例来源:origin: ch.qos.logback/logback-classic
public <N extends Enum<?>> String getColumnName(N columnName) {
return columnName.toString().toLowerCase();
}
代码示例来源:origin: apache/flink
/**
* Set the value of the <code>name</code> property to the given type. This
* is equivalent to <code>set(<name>, value.toString())</code>.
* @param name property name
* @param value new value
*/
public <T extends Enum<T>> void setEnum(String name, T value) {
set(name, value.toString());
}
代码示例来源:origin: apache/flink
/**
* Set the value of the <code>name</code> property to the given type. This
* is equivalent to <code>set(<name>, value.toString())</code>.
* @param name property name
* @param value new value
*/
public <T extends Enum<T>> void setEnum(String name, T value) {
set(name, value.toString());
}
代码示例来源:origin: apache/flink
@Override
public String toString() {
return super.toString().replace('_', ' ');
}
代码示例来源:origin: thinkaurelius/titan
@Override
public String toString() {
return super.toString().toLowerCase();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Case insensitive alternative to {@link Enum#valueOf(Class, String)}.
* @param <E> the concrete Enum type
* @param enumValues the array of all Enum constants in question, usually per {@code Enum.values()}
* @param constant the constant to get the enum value of
* @throws IllegalArgumentException if the given constant is not found in the given array
* of enum values. Use {@link #containsConstant(Enum[], String)} as a guard to avoid this exception.
*/
public static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, String constant) {
for (E candidate : enumValues) {
if (candidate.toString().equalsIgnoreCase(constant)) {
return candidate;
}
}
throw new IllegalArgumentException("Constant [" + constant + "] does not exist in enum type " +
enumValues.getClass().getComponentType().getName());
}
代码示例来源:origin: Graylog2/graylog2-server
@JsonValue
@Override
public String toString() {
return super.toString().toLowerCase(Locale.ENGLISH);
}
}
代码示例来源:origin: thinkaurelius/titan
public static final<E extends Enum> E getEnumValue(String str, Class<E> enumClass) {
str = str.trim();
if (StringUtils.isBlank(str)) return null;
for (E e : enumClass.getEnumConstants()) {
if (e.toString().equalsIgnoreCase(str)) return e;
}
throw new IllegalArgumentException("Invalid enum string provided for ["+enumClass+"]: " + str);
}
代码示例来源:origin: prestodb/presto
public static EnumValues constructFromToString(MapperConfig<?> config, Class<Enum<?>> enumClass)
{
Class<? extends Enum<?>> cls = ClassUtil.findEnumType(enumClass);
Enum<?>[] values = cls.getEnumConstants();
if (values != null) {
SerializableString[] textual = new SerializableString[values.length];
for (Enum<?> en : values) {
textual[en.ordinal()] = config.compileString(en.toString());
}
return new EnumValues(enumClass, textual);
}
throw new IllegalArgumentException("Cannot determine enum constants for Class "+enumClass.getName());
}
代码示例来源:origin: redisson/redisson
public static EnumValues constructFromToString(MapperConfig<?> config, Class<Enum<?>> enumClass)
{
Class<? extends Enum<?>> cls = ClassUtil.findEnumType(enumClass);
Enum<?>[] values = cls.getEnumConstants();
if (values != null) {
SerializableString[] textual = new SerializableString[values.length];
for (Enum<?> en : values) {
textual[en.ordinal()] = config.compileString(en.toString());
}
return new EnumValues(enumClass, textual);
}
throw new IllegalArgumentException("Cannot determine enum constants for Class "+enumClass.getName());
}
代码示例来源:origin: redisson/redisson
@Override
public final void serialize(Enum<?> en, JsonGenerator gen, SerializerProvider serializers)
throws IOException
{
// [JACKSON-684]: serialize as index?
if (_serializeAsIndex(serializers)) {
gen.writeNumber(en.ordinal());
return;
}
// [databind#749]: or via toString()?
if (serializers.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)) {
gen.writeString(en.toString());
return;
}
gen.writeString(_values.serializedValueFor(en));
}
代码示例来源:origin: spring-projects/spring-framework
protected TransactionAttribute parseTransactionAnnotation(AnnotationAttributes attributes) {
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
rbta.setPropagationBehaviorName(
RuleBasedTransactionAttribute.PREFIX_PROPAGATION + attributes.getEnum("value").toString());
List<RollbackRuleAttribute> rollbackRules = new ArrayList<>();
for (Class<?> rbRule : attributes.getClassArray("rollbackOn")) {
rollbackRules.add(new RollbackRuleAttribute(rbRule));
}
for (Class<?> rbRule : attributes.getClassArray("dontRollbackOn")) {
rollbackRules.add(new NoRollbackRuleAttribute(rbRule));
}
rbta.setRollbackRules(rollbackRules);
return rbta;
}
代码示例来源:origin: prestodb/presto
@Override
public final void serialize(Enum<?> en, JsonGenerator gen, SerializerProvider serializers)
throws IOException
{
// [JACKSON-684]: serialize as index?
if (_serializeAsIndex(serializers)) {
gen.writeNumber(en.ordinal());
return;
}
// [databind#749]: or via toString()?
if (serializers.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)) {
gen.writeString(en.toString());
return;
}
gen.writeString(_values.serializedValueFor(en));
}
内容来源于网络,如有侵权,请联系作者删除!