public static ApplicationStatisticsInfo mergeApplicationStatisticsInfo(
      Collection<ApplicationStatisticsInfo> appStatistics) {
    ApplicationStatisticsInfo result = new ApplicationStatisticsInfo();
    Map<String, StatisticsItemInfo> statisticsItemMap = new HashMap<>();

    appStatistics.stream().forEach(appStatistic -> {
      List<StatisticsItemInfo> statisticsItemInfos = appStatistic.getStatItems();
      for (StatisticsItemInfo statisticsItemInfo : statisticsItemInfos) {

        String statisticsItemKey =
            statisticsItemInfo.getType() + "_" + statisticsItemInfo.getState().toString();

        StatisticsItemInfo statisticsItemValue;
        if (statisticsItemMap.containsKey(statisticsItemKey)) {
          statisticsItemValue = statisticsItemMap.get(statisticsItemKey);
          long statisticsItemValueCount = statisticsItemValue.getCount();
          long statisticsItemInfoCount = statisticsItemInfo.getCount();
          long newCount = statisticsItemValueCount + statisticsItemInfoCount;
          statisticsItemValue.setCount(newCount);
        } else {
          statisticsItemValue = new StatisticsItemInfo(statisticsItemInfo);
        }

        statisticsItemMap.put(statisticsItemKey, statisticsItemValue);
      }
    });

    if (!statisticsItemMap.isEmpty()) {
      result.getStatItems().addAll(statisticsItemMap.values());
    }

    return result;
  }
@Test
  public void testMergeDiffApplicationStatisticsInfo() {
    ApplicationStatisticsInfo infoA = new ApplicationStatisticsInfo();
    StatisticsItemInfo item1 = new StatisticsItemInfo(YarnApplicationState.ACCEPTED, "*", 10);
    StatisticsItemInfo item2 =
        new StatisticsItemInfo(YarnApplicationState.NEW_SAVING, "test1", 20);
    infoA.add(item1);
    infoA.add(item2);

    ApplicationStatisticsInfo infoB = new ApplicationStatisticsInfo();
    StatisticsItemInfo item3 =
        new StatisticsItemInfo(YarnApplicationState.NEW_SAVING, "test1", 30);
    StatisticsItemInfo item4 = new StatisticsItemInfo(YarnApplicationState.FINISHED, "test3", 40);
    infoB.add(item3);
    infoB.add(item4);

    List<ApplicationStatisticsInfo> lists = new ArrayList<>();
    lists.add(infoA);
    lists.add(infoB);

    ApplicationStatisticsInfo mergeInfo =
        RouterWebServiceUtil.mergeApplicationStatisticsInfo(lists);

    Assert.assertEquals(3, mergeInfo.getStatItems().size());
    List<StatisticsItemInfo> mergeInfoStatItems = mergeInfo.getStatItems();

    StatisticsItemInfo item1Result = null;
    StatisticsItemInfo item2Result = null;
    StatisticsItemInfo item3Result = null;

    for (StatisticsItemInfo item : mergeInfoStatItems) {
      // ACCEPTED
      if (item.getState() == YarnApplicationState.ACCEPTED) {
        item1Result = item;
      }

      // NEW_SAVING
      if (item.getState() == YarnApplicationState.NEW_SAVING) {
        item2Result = item;
      }

      // FINISHED
      if (item.getState() == YarnApplicationState.FINISHED) {
        item3Result = item;
      }
    }

    Assert.assertEquals(YarnApplicationState.ACCEPTED, item1Result.getState());
    Assert.assertEquals(item1.getCount(), item1Result.getCount());
    Assert.assertEquals(YarnApplicationState.NEW_SAVING, item2Result.getState());
    Assert.assertEquals((item2.getCount() + item3.getCount()), item2Result.getCount());
    Assert.assertEquals(YarnApplicationState.FINISHED, item3Result.getState());
    Assert.assertEquals(item4.getCount(), item3Result.getCount());
  }