use of io.leopard.lang.inum.Inum in project leopard by tanhaichao.
the class LeopardBeanPropertyRowMapper method toBitEnumList.
/**
* 枚举位运算,将数据库中的数字转换成枚举列表
*
* @param json
* @param elementType
* @param field
* @return
*/
@SuppressWarnings("unchecked")
protected static <T> List<T> toBitEnumList(String json, Class<T> elementType, Field field) {
int value = Integer.parseInt(json);
@SuppressWarnings({ "rawtypes" }) Map<Object, Enum<?>> map = EnumUtil.toMap((Class<Enum>) elementType);
Collection<Enum<?>> constants = map.values();
List<T> list = new ArrayList<T>();
for (Enum<?> constant : constants) {
Inum inum = (Inum) constant;
int constantKey = inum.getKey();
if ((constantKey & value) > 0) {
list.add((T) constant);
}
}
return list;
}
Aggregations