diff options
author | James Moger <james.moger@gmail.com> | 2011-08-07 15:53:18 -0400 |
---|---|---|
committer | James Moger <james.moger@gmail.com> | 2011-08-07 15:53:18 -0400 |
commit | 684838def9e1646c266ffb46bbc65b5dfdc8f14d (patch) | |
tree | ab0625631b4c845ee4d9b2e48b12035df13a038b /src/com/iciql/util | |
parent | 0c5463e7372fe4c47341dcf0c48bdd94682d0c7c (diff) | |
download | iciql-684838def9e1646c266ffb46bbc65b5dfdc8f14d.tar.gz iciql-684838def9e1646c266ffb46bbc65b5dfdc8f14d.zip |
Finished enum query support (issue 4)
Diffstat (limited to 'src/com/iciql/util')
-rw-r--r-- | src/com/iciql/util/Utils.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/com/iciql/util/Utils.java b/src/com/iciql/util/Utils.java index dac30fc..b8e2d60 100644 --- a/src/com/iciql/util/Utils.java +++ b/src/com/iciql/util/Utils.java @@ -275,6 +275,25 @@ public class Utils { throw new IciqlException("Can not convert the value {0} from {1} to {2}", o, currentType, targetType);
}
+ public static Object convertEnum(Enum<?> o, EnumType type) {
+ if (o == null || type == null) {
+ return null;
+ }
+ switch (type) {
+ case ORDINAL:
+ return o.ordinal();
+ case ENUMID:
+ if (!EnumId.class.isAssignableFrom(o.getClass())) {
+ throw new IciqlException("Can not convert the enum {0} using ENUMID", o);
+ }
+ EnumId enumid = (EnumId) o;
+ return enumid.enumId();
+ case STRING:
+ default:
+ return o.name();
+ }
+ }
+
public static Object convertEnum(Object o, Class<?> targetType, EnumType type) {
if (o == null) {
return null;
|