验证条件是否满足
最近做个项目维护时,客户要重新修改过滤的真条件,因为本来就是维护项目加上又增加新条件并且条件还存在些关系,开始做的时候真有点找不到北的感觉。
一开始用&&和||拼接了老长的一堆判断条件,那个条件长度看起来简直让人想吐,而且修改后测试bug的出现是一个接一个。
后来没办法直接直接删了重新写过,把条件一个一个分解找出其中存在的可能情况逐一处理,虽代码看起来比以前更多,但条理显得更加清晰。
附上判断是否满足指定条件方法中一部份代码,其过程就是一步一步分解判断条件。
if(autoBidding.isMustComJingzhi() && bidRequest.getBidRequestType() == Const.BIDREQUEST_TYPE_JINGZHI){
if(autoBidding.isMustJingZhiMonthLimit() && !autoBidding.isMustJingZhiDayLimit()){
if(bidRequest.getReturnType() != Const.RETURN_TYPE_MONTH_INTEREST_PRINCIPAL && bidRequest.getReturnType() != Const.RETURN_TYPE_MONTH_INTEREST){
return false;
}
if(bidRequest.getMonthes2Return() > autoBidding.getJingzhiMaxMonth2Return()
|| bidRequest.getMonthes2Return() < autoBidding.getJingzhiMinMonth2Return()
|| autoBidding.getJingzhiMaxMonth2Return() < autoBidding.getJingzhiMinMonth2Return()
|| bidRequest.getMonthes2Return() <= 0){
return false;
}
}else if(!autoBidding.isMustJingZhiMonthLimit() && autoBidding.isMustJingZhiDayLimit()){
if(bidRequest.getReturnType() != Const.RETURN_TYPE_DAY){
return false;
}
if(bidRequest.getMonthes2Return() > autoBidding.getJingzhiMaxDay2Return()
|| bidRequest.getMonthes2Return() < autoBidding.getJingzhiMinDay2Return()
|| autoBidding.getJingzhiMaxDay2Return() < autoBidding.getJingzhiMinDay2Return()
|| bidRequest.getMonthes2Return() <= 0){
return false;
}
}else if(autoBidding.isMustJingZhiMonthLimit() && autoBidding.isMustJingZhiDayLimit()){
if(autoBidding.isMustJingzhiRetunType()){
return false;
}
if(bidRequest.getReturnType() == Const.RETURN_TYPE_MONTH_INTEREST_PRINCIPAL || bidRequest.getReturnType() == Const.RETURN_TYPE_MONTH_INTEREST){
if(bidRequest.getMonthes2Return() > autoBidding.getJingzhiMaxMonth2Return()
|| bidRequest.getMonthes2Return() < autoBidding.getJingzhiMinMonth2Return()
|| autoBidding.getJingzhiMaxMonth2Return() < autoBidding.getJingzhiMinMonth2Return()
|| bidRequest.getMonthes2Return() <= 0){
return false;
}
}else if(bidRequest.getReturnType() == Const.RETURN_TYPE_DAY){
if(bidRequest.getMonthes2Return() > autoBidding.getJingzhiMaxDay2Return()
|| bidRequest.getMonthes2Return() < autoBidding.getJingzhiMinDay2Return()
|| autoBidding.getJingzhiMaxDay2Return() < autoBidding.getJingzhiMinDay2Return()
|| bidRequest.getMonthes2Return() <= 0){
return false;
}
}
}
}