Java-过滤器返回空值

时间:2018-11-05 13:00:53

标签: java spring spring-mvc filter filtering

我正在尝试过滤列表,但每次搜索都返回空值。我尝试了所有可能的方法,但没有任何反应。请帮助我

public class IssuerCreditDetailsUpdate implements ItemProcessor<Isin_Master, Issuer_credit_rating_details> {

    protected final Logger logger = Logger.getLogger(this.getClass().getName());
    static ArrayList<Credit_rating_details> Credit = new ArrayList<Credit_rating_details>();
    private String validCreditRating = null;

    @Override
    public Issuer_credit_rating_details process(Isin_Master item) throws Exception {
        Issuer_credit_rating_details row = new Issuer_credit_rating_details();
        if(isCreditRatingValid(item.getIssuer_Id())!= null) {   
                        row.setIssuer_id(item.getIssuer_Id());
            row.setName_of_issuer(item.getIssuerName());

            return row;
        }

        return null;
    }

    private String isCreditRatingValid(String issuerid) {
        System.out.println(Credit.stream().filter(i-> i.getIssuer_id().contains(issuerid)).collect(Collectors.toList()));
        List<Credit_rating_details> result = Credit.stream().filter(i-> i.getIssuer_id().contains(issuerid)).collect(Collectors.toList());
        if(!result.isEmpty() ) {

            validCreditRating = result.get(0).getCredit_rating();
            return result.get(0).getCredit_rating();
        }else {
            return null;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

可能i-> i.getIssuer_id().contains(issuerid)与您期望的方式不匹配。 Credit_rating_details.getIssuer_id()返回的类型是什么?它也是字符串吗? 输入的issuerid和Credit_rating_details issuer_id是否可能在不同的情况下?
尝试i-> i.getIssuer_id().equalsIgnoreCase(issuerid)看看是否得到不同的结果。