17 April 2018

枚举抽象类实现分享抑制功能校验

1.背景:手动配置规则,灵活控制,任何一个维度的组合数据校验限制住了,停止

2.规则配置

3.实现

public enum EnumOperation {

   public abstract boolean execute(double left, double right);

   GTE(">=") {
        @Override
        public boolean execute(double left, double right) {
            return left - right >= 0;
        }
    },
    LTE("<=") {
        @Override
        public boolean execute(double left, double right) {
            return left - right >= 0;
        }
    };


    public String getOperator() {
        return operator;
    }

    private final String operator;

    EnumOperation(String s) {
        this.operator = s;
    }

}

4.调用

List<EnumOperation> operationList=new ArrayList<EnumOperation>();//实际为查询结果

for(EnumOperation operation:operationList){
    operation.execute(1.2,1.3);
}


blog comments powered by Disqus