123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 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;
- }
- }
|