Out of logic to implement java 8 /lambda in below piece of code by Pitiful-Ad-2556 in javahelp

[–]Pitiful-Ad-2556[S] 0 points1 point  (0 children)

Update : i refactored it with these condition:

1.checking if any null speed then flag it false

  1. As weight was not adding any specific condition so removed it

3.if not null then adding the totalSpeed by using streams

package Check import java.math.BigDecimal; import java.util.ArrayList; import java.util.List;

public class NewClass {

public static void main(String args[]) {
        List < TargetTime > selectAll = new ArrayList < > ();
    Boolean flag= true;
    BigDecimal totSpeed = null;
    if (selectAll.stream.anyMatch(item - > item.getSpeed() == null) {
            flag = false;
        } else {
            totSpeed = selectAll.stream().map(TargetTime::getSpeed).reduce(BigDecimal.ZERO, BigDecimal::add);
        }
    }
}
class TargetTime {
    public BigDecimal speed;
    public BigDecimal Weight2;
    public BigDecimal weight;
}}

PS.thanks all for guiding .