Stream流代替双重for循环小记

// 总急减速
AtomicReference<Integer> totalRd = new AtomicReference<>(0);
// 总急加速
AtomicReference<Integer> totalRa = new AtomicReference<>(0);
// 总急转弯
AtomicReference<Integer> totalAst = new AtomicReference<>(0);

AtomicInteger index = new AtomicInteger(0);
gpsList.stream().forEach(gps -> {
    index.getAndIncrement();
    AtomicInteger index2 = new AtomicInteger(0);
    traceLists.stream().anyMatch(trace -> {
        index2.getAndIncrement();
        if (index.get() == index2.get()){
            trace.setASharpTurn(gps.getASharpTurn());
            trace.setRapidDeceleration(gps.getRapidDeceleration());
            trace.setRapidAcceleration(gps.getRapidAcceleration());
            totalRd.updateAndGet(v -> v + gps.getRapidDeceleration());
            totalRa.updateAndGet(v -> v + gps.getRapidAcceleration());
            totalAst.updateAndGet(v -> v + gps.getASharpTurn());
        }
        return false;
    });
});
上一篇:Nodejs + Navicat 15 搭建后端服务器


下一篇:web服务器?志格式配置