最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

通過java記錄數(shù)據(jù)持續(xù)變化時間代碼解析

 更新時間:2020年01月15日 11:23:09   作者:鄭某人1  
這篇文章主要介紹了通過java記錄數(shù)據(jù)持續(xù)變化時間代碼解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

這篇文章主要介紹了通過java記錄數(shù)據(jù)持續(xù)變化時間代碼解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

1.需求:獲取count為null和不為null的持續(xù)變化

[{count=0, time=0},
{count=10, time=1000},
{count=20, time=2000},
{count=30, time=3000},
{count=40, time=4000},
{count=null, time=5000},
{count=null, time=6000},
{count=null, time=7000},
{count=null, time=8000},
{count=null, time=9000},
{count=100, time=10000},
{count=110, time=11000},
{count=120, time=12000},
{count=130, time=13000},
{count=140, time=14000}]

2.代碼如下:

package com.stop;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * static boolean temp_flag; // 記錄容器
  public void execute(boolean flag) {
    if (temp_flag == flag) {
      // 沒有變化
    } else {
      if (flag == false) {
        // 上次是true,本次是false
      } else {
        // 上次是false本次是true
      }
    }
  }
 */
public class Test {
  public static List<Map<String, Object>> buildList() {
    List<Map<String, Object>> items = new ArrayList<>();
    for(int i=0;i<5;i++) {
      Map<String,Object> map = new HashMap<>();
      map.put("time", i*1000);
      map.put("count", i*10);
      items.add(map);
    }
    for(int i=5;i<10;i++) {
      Map<String,Object> map = new HashMap<>();
      map.put("time", i*1000);
      map.put("count", null);
      items.add(map);
    }
    for(int i=10;i<15;i++) {
      Map<String,Object> map = new HashMap<>();
      map.put("time", i*1000);
      map.put("count", i*10);
      items.add(map);
    }
    return items;
  }



  public static void main(String[] args) {
    // 構造數(shù)據(jù)
    List<Map<String, Object>> items = buildList();
    
    List<Map<String, Object>> list = new ArrayList<>();
    boolean isStop = false;// 記錄容器
    for (int i = 0; i < items.size(); i++) {
      boolean flag = items.get(i).get("count") == null;
      if (i == 0) {
        Map<String, Object> map = new HashMap<>();
        if (flag) {
          map.put("stop", items.get(i).get("time"));
          isStop = true;
        } else {
          map.put("recover", items.get(i).get("time"));
        }
        list.add(map);
        continue;
      }
      if (isStop == flag) {
        // 沒有變化
      } else {
        isStop = flag;
        Map<String, Object> map = new HashMap<>();
        if (!flag) {
          // 上次是true,本次是false
          map.put("recover", items.get(i).get("time"));
        } else {
          // 上次是false本次是true
          map.put("stop", items.get(i).get("time"));
        }
        list.add(map);
      }
    }
    System.out.println(list);
  }

}

3.運行main方法結果

[{recover=0}, {stop=5000}, {recover=10000}]

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

平谷区| 高尔夫| 张北县| 蒙阴县| 叶城县| 金溪县| 湖州市| 库尔勒市| 南康市| 开化县| 自贡市| 千阳县| 鸡泽县| 青铜峡市| 大新县| 呈贡县| 灌南县| 朝阳区| 平阳县| 叙永县| 东乡县| 巴塘县| 固原市| 芮城县| 安阳县| 泰来县| 天峨县| 望谟县| 苗栗市| 安顺市| 额尔古纳市| 册亨县| 静海县| 巴马| 阿城市| 云阳县| 宿迁市| 肇东市| 山东省| 宜章县| 洪湖市|