package cn.com.qmth.examcloud.commons.helpers; import java.io.Serializable; import org.apache.commons.lang3.StringUtils; import cn.com.qmth.examcloud.commons.util.StringUtil; /** * 动态枚举 * * @author WANGWEI * @date 2018年8月23日 * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved. */ public final class DynamicEnum implements Serializable { private static final long serialVersionUID = -694709140246715214L; /** * ID */ private Long id; /** * name */ private String name; /** * 描述 */ private String desc; /** * 值类型 */ private String valueType; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; } public String getValueType() { return valueType; } public void setValueType(String valueType) { this.valueType = valueType; } /** * 是否合法 * * @author WANGWEI * @param value * @return */ public Boolean isLegal(String value) { if (StringUtils.isNotBlank(value) && null != valueType) { BasicDataType dataType = BasicDataType.valueOf(valueType); if (dataType.equals(BasicDataType.BOOLEAN)) { try { StringUtil.toBoolean(value); return true; } catch (Exception e) { return false; } } else if (dataType.equals(BasicDataType.INTEGER)) { try { StringUtil.toInteger(value); return true; } catch (Exception e) { return false; } } else if (dataType.equals(BasicDataType.LONG)) { try { StringUtil.toLong(value); return true; } catch (Exception e) { return false; } } } return true; } }