Search in sources :

Example 1 with Inum

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;
}
Also used : DynamicEnum(io.leopard.lang.inum.daynamic.DynamicEnum) ArrayList(java.util.ArrayList) Inum(io.leopard.lang.inum.Inum)

Aggregations

Inum (io.leopard.lang.inum.Inum)1 DynamicEnum (io.leopard.lang.inum.daynamic.DynamicEnum)1 ArrayList (java.util.ArrayList)1