@Test public void testMergeMaps() { Map<String, Long> m1 = new HashMap<>(); m1.put("enhet-1", 2l); m1.put("enhet-2", 3l); Map<String, Long> m2 = new HashMap<>(); m2.put("enhet-2", 2l); m2.put("enhet-3", 4l); Map<String, Long> m3 = statController.mergeArendeAndFragaSvarMaps(m1, m2); assertEquals(3, m3.size()); assertEquals((long) 2, (long) m3.get("enhet-1")); assertEquals((long) 5, (long) m3.get("enhet-2")); assertEquals((long) 4, (long) m3.get("enhet-3")); }
Map<String, Long> mergeArendeAndFragaSvarMaps(Map<String, Long> fragaSvarStatsMap, Map<String, Long> arendeStatsMap) { Map<String, Long> mergedMap = new HashMap<>(); Set<String> uniqueEnhetsId = Stream.of(fragaSvarStatsMap.keySet(), arendeStatsMap.keySet()).flatMap(Collection::stream).distinct() .collect(Collectors.toSet()); for (String enhetId : uniqueEnhetsId) { Long sum = (fragaSvarStatsMap.get(enhetId) != null ? fragaSvarStatsMap.get(enhetId) : 0) + (arendeStatsMap.get(enhetId) != null ? arendeStatsMap.get(enhetId) : 0); mergedMap.put(enhetId, sum); } return mergedMap; }
StatModuleApiController extends AbstractApiController { Map<String, Long> mergeArendeAndFragaSvarMaps(Map<String, Long> fragaSvarStatsMap, Map<String, Long> arendeStatsMap) { Map<String, Long> mergedMap = new HashMap<>(); Set<String> uniqueEnhetsId = Stream.of(fragaSvarStatsMap.keySet(), arendeStatsMap.keySet()).flatMap(Collection::stream).distinct() .collect(Collectors.toSet()); for (String enhetId : uniqueEnhetsId) { Long sum = (fragaSvarStatsMap.get(enhetId) != null ? fragaSvarStatsMap.get(enhetId) : 0) + (arendeStatsMap.get(enhetId) != null ? arendeStatsMap.get(enhetId) : 0); mergedMap.put(enhetId, sum); } return mergedMap; } }
StatModuleApiController extends AbstractApiController { Map<String, Long> mergeArendeAndFragaSvarMaps(Map<String, Long> fragaSvarStatsMap, Map<String, Long> arendeStatsMap) { Map<String, Long> mergedMap = new HashMap<>(); Set<String> uniqueEnhetsId = Stream.of(fragaSvarStatsMap.keySet(), arendeStatsMap.keySet()).flatMap(Collection::stream).distinct() .collect(Collectors.toSet()); for (String enhetId : uniqueEnhetsId) { Long sum = (fragaSvarStatsMap.get(enhetId) != null ? fragaSvarStatsMap.get(enhetId) : 0) + (arendeStatsMap.get(enhetId) != null ? arendeStatsMap.get(enhetId) : 0); mergedMap.put(enhetId, sum); } return mergedMap; }  }
StatModuleApiController extends AbstractApiController { Map<String, Long> mergeArendeAndFragaSvarMaps(Map<String, Long> fragaSvarStatsMap, Map<String, Long> arendeStatsMap) { Map<String, Long> mergedMap = new HashMap<>(); Set<String> uniqueEnhetsId = Stream.of(fragaSvarStatsMap.keySet(), arendeStatsMap.keySet()).flatMap(Collection::stream).distinct() .collect(Collectors.toSet()); for (String enhetId : uniqueEnhetsId) { Long sum = (fragaSvarStatsMap.get(enhetId) != null ? fragaSvarStatsMap.get(enhetId) : 0) + (arendeStatsMap.get(enhetId) != null ? arendeStatsMap.get(enhetId) : 0); mergedMap.put(enhetId, sum); } return mergedMap; }  @GET @Path("/") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getStatistics(); }
StatModuleApiController extends AbstractApiController { Map<String, Long> mergeArendeAndFragaSvarMaps(Map<String, Long> fragaSvarStatsMap, Map<String, Long> arendeStatsMap) { Map<String, Long> mergedMap = new HashMap<>(); Set<String> uniqueEnhetsId = Stream.of(fragaSvarStatsMap.keySet(), arendeStatsMap.keySet()).flatMap(Collection::stream).distinct() .collect(Collectors.toSet()); for (String enhetId : uniqueEnhetsId) { Long sum = (fragaSvarStatsMap.get(enhetId) != null ? fragaSvarStatsMap.get(enhetId) : 0) + (arendeStatsMap.get(enhetId) != null ? arendeStatsMap.get(enhetId) : 0); mergedMap.put(enhetId, sum); } return mergedMap; }  @GET @Path("/") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getStatistics();  }