枚举类可用于对常用的一些常量进行统一管理,降低后续变动代码维护成本。
下面简单创建一个枚举类,代码如下:
package com.ahzx.xed.enums;
import lombok.Getter;
import java.util.Collections;
/**
* DataEffective
*上报数据效验
*/
@Getter
public enum DataEffective {
/**
* 公共资源交易记录查询接口
*/
GUARANTEE_MODE("guaranteeMode", new String[]{"0","1","2","3","4","5","6","7","99"}),
;
private String key;
private String[] value;
DataEffective(String key, String[] value) {
this.key = key;
this.value = value;
}
}
数据效验中枚举类应用,部分代码如下:
List<FinancingRequirement> dataList = Db.use(dataSource).query(BizSqls.FINANCING_REQUIREMENTS+condition)
.stream()
.map(entity -> entity.toBeanIgnoreCase(FinancingRequirement.class))
.filter(f -> StrUtil.isNotBlank(f.getUniscId())
&& StrUtil.isNotBlank(f.getGuaranteeMode())
&& StrUtil.isNotBlank(f.getOrientation())
&& Arrays.asList(DataEffective.GUARANTEE_MODE.getValue()).contains(f.getGuaranteeMode())
)
.peek(f -> f.setPlatformId(appProps.getPlatformId()))
.collect(Collectors.toList());