List of usage examples for java.util.stream Collectors toMap
public static <T, K, U> Collector<T, ?, Map<K, U>> toMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper)
From source file:io.spring.initializr.web.mapper.DependencyMetadataV21JsonMapper.java
@Override public String write(DependencyMetadata metadata) { JSONObject json = new JSONObject(); json.put("bootVersion", metadata.getBootVersion().toString()); json.put("dependencies", metadata.getDependencies().entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> mapDependency(entry.getValue())))); json.put("repositories", metadata.getRepositories().entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> mapRepository(entry.getValue())))); json.put("boms", metadata.getBoms().entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> mapBom(entry.getValue())))); return json.toString(); }
From source file:spring.travel.site.auth.CookieDecoder.java
public Map<String, String> decode(String cookie) throws AuthException { String[] parts = cookie.split("-", 2); if (parts.length != 2) { return Collections.emptyMap(); }//from ww w. ja va 2 s .co m String signature = parts[0]; String encoded = parts[1]; if (!verifier.verify(encoded, signature)) { return Collections.emptyMap(); } return Arrays.asList(encoded.split("&")).stream().map(keyValue -> keyValue.split("=")).collect( Collectors.toMap(arr -> urlDecode(arr[0]), arr -> arr.length > 1 ? urlDecode(arr[1]) : "")); }
From source file:com.create.application.configuration.properties.EclipseLinkProperties.java
public Map<String, Object> getVendorProperties() { return eclipselink.entrySet().stream().collect(Collectors.toMap(toPrefixedProperty(), Entry::getValue)); }
From source file:org.obiba.mica.micaConfig.service.helper.StudyIdAggregationMetaDataHelper.java
@Cacheable(value = "aggregations-metadata", key = "'study'") public Map<String, AggregationMetaDataProvider.LocalizedMetaData> getStudies() { try {/* w ww. j a v a2 s . com*/ List<BaseStudy> studies = sudo(() -> publishedStudyService.findAll()); return studies.stream().collect(Collectors.toMap(AbstractGitPersistable::getId, study -> { if (study instanceof HarmonizationStudy) { return new AggregationMetaDataProvider.LocalizedMetaData(study.getAcronym(), study.getName(), study.getClassName()); } return new AggregationMetaDataProvider.LocalizedMetaData(study.getAcronym(), study.getName(), study.getClassName(), yearToString(study.getModel().get("startYear")), yearToString(study.getModel().get("endYear"))); })); } catch (Exception e) { log.debug("Could not build Study aggregation metadata {}", e); return Maps.newHashMap(); } }
From source file:org.ow2.proactive.procci.service.transformer.TransformerManager.java
@Autowired public TransformerManager(List<TransformerProvider> transformerProviders) { transformerPerType = transformerProviders.stream() .collect(Collectors.toMap(TransformerProvider::getType, Function.identity())); }
From source file:eu.openg.aws.s3.internal.FakeS3Object.java
private static Map<String, String> serializeUserMetadata(Map<String, String> metadata) { return metadata.entrySet().stream() .collect(Collectors.toMap(entry -> entry.getKey().toLowerCase(), Map.Entry::getValue)); }
From source file:am.ik.categolj3.api.tag.InMemoryTagService.java
@EventListener public void handlePutEntry(EntryPutEvent.Bulk event) { if (log.isInfoEnabled()) { log.info("bulk put ({})", event.getEvents().size()); }/* w ww. j av a 2 s. com*/ tags.putAll(event.getEvents().stream().map(EntryPutEvent::getEntry) .filter(e -> !CollectionUtils.isEmpty(e.getFrontMatter().getTags())) .collect(Collectors.toMap(Entry::getEntryId, e -> e.getFrontMatter().getTags()))); }
From source file:am.ik.categolj3.api.category.InMemoryCategoryService.java
@EventListener public void handlePutEntry(EntryPutEvent.Bulk event) { if (log.isInfoEnabled()) { log.info("bulk put ({})", event.getEvents().size()); }/* w w w . j a v a 2 s .co m*/ categories.putAll(event.getEvents().stream().map(EntryPutEvent::getEntry) .filter(e -> !CollectionUtils.isEmpty(e.getFrontMatter().getCategories())) .collect(Collectors.toMap(Entry::getEntryId, e -> e.getFrontMatter().getCategories()))); }
From source file:io.galeb.router.tests.hostselectors.AbstractHashHostSelectorTest.java
void doRandomTest(double errorPercentMax, double limitOfNotHitsPercent, int numPopulation) { final HttpServerExchange exchange = new HttpServerExchange(null); final Host[] newHosts = numPopulation < hosts.length ? Arrays.copyOf(hosts, numPopulation) : hosts; final Map<Integer, String> remains = IntStream.rangeClosed(0, newHosts.length - 1).boxed() .collect(Collectors.toMap(x -> x, x -> "")); for (int retry = 1; retry <= NUM_RETRIES; retry++) { final SummaryStatistics statisticsOfResults = new SummaryStatistics(); final Map<Integer, Integer> mapOfResults = new HashMap<>(); new Random().ints(numPopulation).map(Math::abs).forEach(x -> { changeExchange(exchange, x); int result = getResult(exchange, newHosts); Integer lastCount = mapOfResults.get(result); remains.remove(result);/* ww w .ja va 2 s.c om*/ mapOfResults.put(result, lastCount != null ? ++lastCount : 0); }); mapOfResults.entrySet().stream().mapToDouble(Map.Entry::getValue) .forEach(statisticsOfResults::addValue); double errorPercent = (statisticsOfResults.getStandardDeviation() / numPopulation) * 100; assertThat(errorPercent, lessThan(errorPercentMax)); } final List<Integer> listOfNotHit = remains.entrySet().stream().map(Map.Entry::getKey).collect(toList()); assertThat(listOfNotHit.size(), lessThanOrEqualTo((int) (newHosts.length * (limitOfNotHitsPercent / 100)))); }
From source file:com.synopsys.integration.blackduck.codelocation.CodeLocationBatchOutput.java
public CodeLocationBatchOutput(List<T> outputs) { successfulCodeLocationNamesToExpectedNotificationCounts = outputs.stream().peek(this.outputs::add) .filter(output -> Result.SUCCESS == output.getResult()) .filter(output -> StringUtils.isNotBlank(output.getCodeLocationName())).collect(Collectors.toMap( CodeLocationOutput::getCodeLocationName, CodeLocationOutput::getExpectedNotificationCount)); }