编程注意事项

来源:互联网 发布:linux 内核 smp 编辑:程序博客网 时间:2024/05/17 04:50
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
原创粉丝点击