编程注意事项

List<FundProductStockAllocationData> stockFundProductStockAllocationDataList = stockFundProductStockAllocationDataFetcher.getStockFundProductStockAllocationDataListForSingleFund(fundcode, startDate,endDate);
        if(stockFundProductStockAllocationDataList != null &&stockFundProductStockAllocationDataList.size()>0){
            if(startDate!=null||endDate!=null){
                return ResponseUtil.getResponse(stockFundProductStockAllocationDataList);
            }
            String publishDate = stockFundProductStockAllocationDataList.get(0).getPublishDate();
            List<FundProductStockAllocationData> returnList = new ArrayList();
            for(FundProductStockAllocationData stock:stockFundProductStockAllocationDataList){
                if(publishDate==null||publishDate.equals(stock.getPublishDate())){
                    returnList.add(stock);
                }else {
                    break;
                }
            }
        	return ResponseUtil.getResponse(returnList);

在上述的这段比较简短的代码中犯了很多的错误。

首先逻辑判断不清楚,思维不严密。

根据传入的参数来判断是否需要进行筛选,如果没有传入时间参数则是为了获取最新的数据,需要筛选,否则不需要。

还有在进行时间是否为最新的判断时候,我开始没有考虑到字符串为空的情况,这样如果遇到字符串为空的的时候就会报空指针异常。

另外我把stock.getPublishDate()放在字符串比较函数的前面来判断字符串相等,忽略了如果再次为空的异常情况。

谨记!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值