@Test public void testFlattenMap() { Map<String, Collection<String>> testData = new HashMap<String, Collection<String>>() { { put("key1", Arrays.asList(new String[] { "value1", "value2" })); put("key2", Arrays.asList(new String[] { "value3", "value4" })); } }; String[] expectedResult = new String[] { "key1:value1", "key1:value2", "key2:value3", "key2:value4" }; List<String> flattenData = classUnderTest.flattenMapToList(testData); Assert.assertArrayEquals("The map was flatten correctly", expectedResult, flattenData.toArray()); }
protected List<String> flattenMapToList(Map<String, Collection<String>> mapOfCollections) { List<String> flatList = new ArrayList<>(); mapOfCollections.forEach((provider, identifiers) -> { identifiers.stream().forEach(identifier -> flatList.add(provider + ":" + identifier)); }); return flatList; }
CatalogIdentifierDatasource extends SlingSafeMethodsServlet { protected List<String> flattenMapToList(Map<String, Collection<String>> mapOfCollections) { List<String> flatList = new ArrayList<>(); mapOfCollections.forEach((provider, identifiers) -> { identifiers.stream().forEach(identifier -> flatList.add(provider + ":" + identifier)); }); return flatList; } }
CatalogIdentifierDatasource extends SlingSafeMethodsServlet { protected List<String> flattenMapToList(Map<String, Collection<String>> mapOfCollections) { List<String> flatList = new ArrayList<>(); mapOfCollections.forEach((provider, identifiers) -> { identifiers.stream().forEach(identifier -> flatList.add(provider + ":" + identifier)); }); return flatList; }  }
CatalogIdentifierDatasource extends SlingSafeMethodsServlet { protected List<String> flattenMapToList(Map<String, Collection<String>> mapOfCollections) { List<String> flatList = new ArrayList<>(); mapOfCollections.forEach((provider, identifiers) -> { identifiers.stream().forEach(identifier -> flatList.add(provider + ":" + identifier)); }); return flatList; }   }
CatalogIdentifierDatasource extends SlingSafeMethodsServlet { protected List<String> flattenMapToList(Map<String, Collection<String>> mapOfCollections) { List<String> flatList = new ArrayList<>(); mapOfCollections.forEach((provider, identifiers) -> { identifiers.stream().forEach(identifier -> flatList.add(provider + ":" + identifier)); }); return flatList; }    }