[JAVA]请JAVA专家帮忙看看,下面代码哪种编写方式更好。
方法一、使用运算符
//话单计费方式配置价格为0免费
final boolean isBillWayFree = null != mainChargeWay
&& mainChargeWay.isBillChargeWay())
&& mainChargeWay.isFreeChargeWay();
//免费情况处理
if (isBillWayFree)
{
//获取日志并打印
final String message = LogResUtils.getChargeRes("Charge.free.zeroprice");
LOG.info(message, MODULE);
//设置免费返回结果
return CHARGESUCCESS;
}
另一种方式:使用If - else 同时提取方法。
//判断当配置为话单计费时0元是否免费
if (isBillWayFree(mainChargeWay))
{
//获取日志并打印
final String message = LogResUtils.getChargeRes("Charge.free.zeroprice");
LOG.info(message, MODULE);
//设置免费返回结果
return CHARGESUCCESS;
}
/**
* 判断当配置为话单计费时0元是否免费
* @param mainChargeWay 具体的扣费方式
* @return boolean true:免费,false:不免费
* @see [类、类#方法、类#成员]
*/
private static boolean isBillWayFree(final IChargeWay mainChargeWay)
{
// 如果扣费方式为空,则返回不免费
if (null == mainChargeWay)
{
return false;
}
// 如果是话单扣费,则判断0元的价格是否写话单 1:写话单 0:不写话单
if (mainChargeWay.isBillChargeWay())
{
// 当且仅当配置为0元的价格不写话单时,返回true:表示免费
return mainChargeWay.isFreeChargeWay();
}
// 其他返回不免费
return false;
}
请大家发表一下意见,哪种方式更好或者其他什么方式更好。