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 testMergeApplicationStatisticsInfo() {
    ApplicationStatisticsInfo infoA = new ApplicationStatisticsInfo();
    ApplicationStatisticsInfo infoB = new ApplicationStatisticsInfo();

    StatisticsItemInfo item1 = new StatisticsItemInfo(YarnApplicationState.ACCEPTED, "*", 10);
    StatisticsItemInfo item2 = new StatisticsItemInfo(YarnApplicationState.ACCEPTED, "*", 20);

    infoA.add(item1);
    infoB.add(item2);

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

    ApplicationStatisticsInfo mergeInfo =
        RouterWebServiceUtil.mergeApplicationStatisticsInfo(lists);
    ArrayList<StatisticsItemInfo> statItem = mergeInfo.getStatItems();

    Assert.assertNotNull(statItem);
    Assert.assertEquals(1, statItem.size());

    StatisticsItemInfo first = statItem.get(0);

    Assert.assertEquals(item1.getCount() + item2.getCount(), first.getCount());
    Assert.assertEquals(item1.getType(), first.getType());
    Assert.assertEquals(item1.getState(), first.getState());
  }