@Test public void convertMyOtherEnum() { hyphenateEnumConverter = new HyphenateEnumConverter(MyOtherEnum.class); MyOtherEnum myOtherEnum = (MyOtherEnum) hyphenateEnumConverter.convert("makingLifeDifficult"); assertEquals(myOtherEnum, MyOtherEnum.makingLifeDifficult); myOtherEnum = (MyOtherEnum) hyphenateEnumConverter.convert("making-life-difficult"); assertEquals(myOtherEnum, MyOtherEnum.makingLifeDifficult); myOtherEnum = (MyOtherEnum) hyphenateEnumConverter.convert("READ__UNCOMMITTED"); assertEquals(myOtherEnum, MyOtherEnum.READ__UNCOMMITTED); myOtherEnum = (MyOtherEnum) hyphenateEnumConverter.convert("read-uncommitted"); assertEquals(myOtherEnum, MyOtherEnum.READ__UNCOMMITTED); }
@Override public E convert(String value) { value = value.trim(); if (value.isEmpty()) { return null; } final String hyphenatedValue = hyphenate(value); final Enum<?> enumValue = values.get(hyphenatedValue); if (enumValue != null) { return enumType.cast(enumValue); } throw new IllegalArgumentException(String.format("Cannot convert %s to enum %s", value, enumType)); }
HyphenateEnumConverter implements Converter<E>, Serializable { @Override public E convert(String value) { value = value.trim(); if (value.isEmpty()) { return null; } final String hyphenatedValue = hyphenate(value); final Enum<?> enumValue = values.get(hyphenatedValue); if (enumValue != null) { return enumType.cast(enumValue); } throw new IllegalArgumentException(String.format("Cannot convert %s to enum %s", value, enumType)); } }
HyphenateEnumConverter implements Converter<E>, Serializable { @Override public E convert(String value) { value = value.trim(); if (value.isEmpty()) { return null; } final String hyphenatedValue = hyphenate(value); final Enum<?> enumValue = values.get(hyphenatedValue); if (enumValue != null) { return enumType.cast(enumValue); } throw new IllegalArgumentException(String.format("Cannot convert %s to enum %s", value, enumType)); } HyphenateEnumConverter(Class<E> enumType); }
HyphenateEnumConverter implements Converter<E>, Serializable { @Override public E convert(String value) { value = value.trim(); if (value.isEmpty()) { return null; } final String hyphenatedValue = hyphenate(value); final Enum<?> enumValue = values.get(hyphenatedValue); if (enumValue != null) { return enumType.cast(enumValue); } throw new IllegalArgumentException(String.format("Cannot convert %s to enum %s", value, enumType)); } HyphenateEnumConverter(Class<E> enumType); static HyphenateEnumConverter<E> of(Class<E> enumType); @Override E convert(String value); }
HyphenateEnumConverter implements Converter<E>, Serializable { @Override public E convert(String value) { value = value.trim(); if (value.isEmpty()) { return null; } final String hyphenatedValue = hyphenate(value); final Enum<?> enumValue = values.get(hyphenatedValue); if (enumValue != null) { return enumType.cast(enumValue); } throw new IllegalArgumentException(String.format("Cannot convert %s to enum %s", value, enumType)); } HyphenateEnumConverter(Class<E> enumType); static HyphenateEnumConverter<E> of(Class<E> enumType); @Override E convert(String value);  }