本文整理了Java中com.google.common.base.Enums.stringConverter()
方法的一些代码示例,展示了Enums.stringConverter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Enums.stringConverter()
方法的具体详情如下:
包路径:com.google.common.base.Enums
类名称:Enums
方法名:stringConverter
[英]Returns a converter that converts between strings and enum values of type enumClass using Enum#valueOf(Class,String) and Enum#name(). The converter will throw an IllegalArgumentException if the argument is not the name of any enum constant in the specified enum.
[中]返回一个转换器,该转换器使用enum#valueOf(Class,String)和enum#name()在enumClass类型的字符串和枚举值之间进行转换。如果参数不是指定枚举中任何枚举常量的名称,则转换器将抛出IllegalArgumentException。
代码示例来源:origin: google/guava
public void testStringConverter_serialization() {
SerializableTester.reserializeAndAssert(Enums.stringConverter(TestEnum.class));
}
代码示例来源:origin: google/guava
@GwtIncompatible // Class.getName()
public void testStringConverter_toString() {
assertEquals(
"Enums.stringConverter(com.google.common.base.EnumsTest$TestEnum.class)",
Enums.stringConverter(TestEnum.class).toString());
}
代码示例来源:origin: google/guava
public void testStringConverter_convertError() {
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
try {
converter.convert("xxx");
fail();
} catch (IllegalArgumentException expected) {
}
}
代码示例来源:origin: google/guava
@GwtIncompatible // NullPointerTester
public void testStringConverter_nullPointerTester() throws Exception {
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicInstanceMethods(converter);
}
代码示例来源:origin: google/guava
public void testStringConverter_nullConversions() {
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
assertNull(converter.convert(null));
assertNull(converter.reverse().convert(null));
}
代码示例来源:origin: google/guava
public void testStringConverter_reverse() {
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
assertEquals("CHEETO", converter.reverse().convert(TestEnum.CHEETO));
assertEquals("HONDA", converter.reverse().convert(TestEnum.HONDA));
assertEquals("POODLE", converter.reverse().convert(TestEnum.POODLE));
}
代码示例来源:origin: google/guava
public void testStringConverter_convert() {
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
assertEquals(TestEnum.CHEETO, converter.convert("CHEETO"));
assertEquals(TestEnum.HONDA, converter.convert("HONDA"));
assertEquals(TestEnum.POODLE, converter.convert("POODLE"));
assertNull(converter.convert(null));
assertNull(converter.reverse().convert(null));
}
代码示例来源:origin: com.github.bingoohuang/spring-redis-cache
@Override
public Object deserialize(String redisValue, Method method) {
return Enums.stringConverter(returnType).convert(redisValue);
}
}
代码示例来源:origin: rinde/RinSim
/**
* Create a parser for {@link Enum}s.
* @param name The name for the value of the option (typically the enum name).
* @param enumClass The class of the enum.
* @param <T> The class of the enum.
* @return A new {@link ArgumentParser} for instances of the specified enum.
*/
public static <T extends Enum<T>> ArgumentParser<T> enumParser(String name,
Class<T> enumClass) {
return asParser(name, Enums.stringConverter(enumClass));
}
代码示例来源:origin: rinde/RinSim
/**
* Create a parser for lists of {@link Enum}s.
* @param name The name for the values of the option (typically the enum name
* with 'list' appended).
* @param enumClass The class of the enum.
* @param <T> The class of the enum.
* @return A new {@link ArgumentParser} for lists of instances of the
* specified enum.
*/
public static <T extends Enum<T>> ArgumentParser<List<T>> enumListParser(
String name, Class<T> enumClass) {
return asListParser(name, Enums.stringConverter(enumClass));
}
代码示例来源:origin: com.google.guava/guava-tests
public void testStringConverter_serialization() {
SerializableTester.reserializeAndAssert(Enums.stringConverter(TestEnum.class));
}
代码示例来源:origin: com.google.guava/guava-tests
@GwtIncompatible // Class.getName()
public void testStringConverter_toString() {
assertEquals(
"Enums.stringConverter(com.google.common.base.EnumsTest$TestEnum.class)",
Enums.stringConverter(TestEnum.class).toString());
}
代码示例来源:origin: com.google.guava/guava-tests
public void testStringConverter_convertError() {
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
try {
converter.convert("xxx");
fail();
} catch (IllegalArgumentException expected) {
}
}
代码示例来源:origin: com.google.guava/guava-tests
@GwtIncompatible // NullPointerTester
public void testStringConverter_nullPointerTester() throws Exception {
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicInstanceMethods(converter);
}
代码示例来源:origin: com.google.guava/guava-tests
public void testStringConverter_nullConversions() {
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
assertNull(converter.convert(null));
assertNull(converter.reverse().convert(null));
}
代码示例来源:origin: com.google.guava/guava-tests
public void testStringConverter_reverse() {
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
assertEquals("CHEETO", converter.reverse().convert(TestEnum.CHEETO));
assertEquals("HONDA", converter.reverse().convert(TestEnum.HONDA));
assertEquals("POODLE", converter.reverse().convert(TestEnum.POODLE));
}
代码示例来源:origin: com.google.guava/guava-tests
public void testStringConverter_convert() {
Converter<String, TestEnum> converter = Enums.stringConverter(TestEnum.class);
assertEquals(TestEnum.CHEETO, converter.convert("CHEETO"));
assertEquals(TestEnum.HONDA, converter.convert("HONDA"));
assertEquals(TestEnum.POODLE, converter.convert("POODLE"));
assertNull(converter.convert(null));
assertNull(converter.reverse().convert(null));
}
内容来源于网络,如有侵权,请联系作者删除!