1. 程式人生 > >判斷一個值在list中物件的某一屬性是否擁有

判斷一個值在list中物件的某一屬性是否擁有

判斷i的值在basicWindPowerList中是否擁有,如果沒有進入if判斷裡面的邏輯

for (double i = 0; i <= 25; i += 0.5){
    String index = String.valueOf(i);
    if (!basicWindPowerList.stream().filter(w->String.valueOf(w.getWind()).equals(index)).findAny().isPresent()){
        Double d =  basicWindPowerService.getShouldPowerByWPPairs(basicWindPowerList,i);
        BigDecimal power = new BigDecimal(d);
        BigDecimal p = power.setScale(1,BigDecimal.ROUND_HALF_DOWN);
        BasicWindPower basicWindPower = new BasicWindPower();
        basicWindPower.setPower(p);
        basicWindPower.setWind(BigDecimal.valueOf(i));
        basicWindPower.setSchemeId(schemeId);
        basicWindPowerList.add(basicWindPower);
    }
}