mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
Support Character.class in EnumConversion
This commit is contained in:
parent
9ce8af1561
commit
c90bd88b54
@ -58,9 +58,9 @@ public class EnumConversion<T> extends FactoryExpressionBase<T> {
|
||||
@Override
|
||||
public T newInstance(Object... args) {
|
||||
if (args[0] != null) {
|
||||
if (args[0] instanceof String) {
|
||||
if (args[0] instanceof String || args[0] instanceof Character) {
|
||||
@SuppressWarnings("unchecked") //The expression type is an enum
|
||||
T rv = (T) Enum.valueOf(getType().asSubclass(Enum.class), (String) args[0]);
|
||||
T rv = (T) Enum.valueOf(getType().asSubclass(Enum.class), (String) args[0].toString());
|
||||
return rv;
|
||||
} else if (args[0] instanceof Number) {
|
||||
return values[((Number) args[0]).intValue()];
|
||||
|
||||
@ -11,7 +11,14 @@ import com.querydsl.core.types.dsl.StringPath;
|
||||
|
||||
public class EnumConversionTest {
|
||||
|
||||
public enum Color { GREEN, BLUE, RED, YELLOW, BLACK, WHITE }
|
||||
public enum Color { GREEN, BLUE, RED, YELLOW, B, W }
|
||||
|
||||
@Test
|
||||
public void nameForCharacter() {
|
||||
EnumPath<Color> color = Expressions.enumPath(Color.class, "path");
|
||||
EnumConversion<Color> conv = new EnumConversion<Color>(color);
|
||||
assertEquals(Color.W, conv.newInstance('W'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void name() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user