Example usage for java.util.stream Collectors toMap

List of usage examples for java.util.stream Collectors toMap

Introduction

In this page you can find the example usage for java.util.stream Collectors toMap.

Prototype

public static <T, K, U> Collector<T, ?, Map<K, U>> toMap(Function<? super T, ? extends K> keyMapper,
        Function<? super T, ? extends U> valueMapper) 

Source Link

Document

Returns a Collector that accumulates elements into a Map whose keys and values are the result of applying the provided mapping functions to the input elements.

Usage

From source file:org.openlmis.fulfillment.web.util.BasicOrderDtoBuilder.java

private Map<UUID, UserDto> getUsers(List<Order> orders) {
    Set<UUID> userIds = orders.stream().map(Order::getCreatedById).collect(Collectors.toSet());
    return userReferenceDataService.findByIds(userIds).stream()
            .collect(Collectors.toMap(BaseDto::getId, Function.identity()));
}

From source file:com.baifendian.swordfish.dao.model.ProjectFlow.java

public Map<String, String> getUserDefinedParamMap() {
    List<Property> propList;

    if (userDefinedParamMap == null && StringUtils.isNotEmpty(userDefinedParams)) {
        propList = JsonUtil.parseObjectList(userDefinedParams, Property.class);
        userDefinedParamMap = propList.stream()
                .collect(Collectors.toMap(Property::getProp, Property::getValue));
    }/*from w w w  .j  a  va  2s  .c o m*/

    return userDefinedParamMap;
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler.KubernetesStatefulSetHandler.java

@Override
public void addRelationships(Map<KubernetesKind, List<KubernetesManifest>> allResources,
        Map<KubernetesManifest, List<KubernetesManifest>> relationshipMap) {
    BiFunction<String, String, String> manifestName = (namespace, name) -> namespace + ":" + name;

    Map<String, KubernetesManifest> services = allResources.getOrDefault(SERVICE, new ArrayList<>()).stream()
            .collect(Collectors.toMap((m) -> manifestName.apply(m.getNamespace(), m.getName()), (m) -> m));

    for (KubernetesManifest manifest : allResources.getOrDefault(STATEFUL_SET, new ArrayList<>())) {
        String serviceName = KubernetesStatefulSetHandler.serviceName(manifest);
        if (StringUtils.isEmpty(serviceName)) {
            continue;
        }/*from  w  ww.jav  a2  s. c o m*/

        String key = manifestName.apply(manifest.getNamespace(), serviceName);

        if (!services.containsKey(key)) {
            continue;
        }

        KubernetesManifest service = services.get(key);
        relationshipMap.put(manifest, Collections.singletonList(service));
    }
}

From source file:com.epam.reportportal.auth.OAuthConfigurationEndpoint.java

/**
 * Returns oauth integration settings//  w  ww .  j a va  2  s.  c o  m
 *
 * @param profileId settings ProfileID
 * @return All defined OAuth integration settings
 */
@RequestMapping(value = "/", method = { GET })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Returns OAuth Server Settings", notes = "'default' profile is using till additional UI implementations")
public Map<String, OAuthDetailsResource> getOAuthSettings(@PathVariable String profileId) {

    ServerSettings settings = repository.findOne(profileId);
    BusinessRule.expect(settings, Predicates.notNull()).verify(ErrorType.SERVER_SETTINGS_NOT_FOUND, profileId);

    return Optional.ofNullable(settings.getoAuth2LoginDetails())
            .map(details -> details.entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey,
                            e -> OAuthDetailsConverters.TO_RESOURCE.apply(e.getValue()))))
            .orElseThrow(() -> new ReportPortalException(ErrorType.OAUTH_INTEGRATION_NOT_FOUND));

}

From source file:com.haulmont.cuba.core.sys.dbupdate.ScriptScanner.java

protected Map<String, ScriptResource> findResourcesByUrlPattern(ResourcePatternResolver resourceResolver,
        String urlPattern) throws IOException {
    try {//from   w w  w .  j ava  2s  .  c o m
        return Arrays.stream(resourceResolver.getResources(urlPattern)).map(ScriptResource::new)
                .collect(Collectors.toMap(ScriptResource::getName, Function.identity()));
    } catch (FileNotFoundException e) {
        //just return empty map
        return Collections.emptyMap();
    }
}

From source file:com.thinkbiganalytics.feedmgr.sla.DefaultServiceLevelAgreementService.java

@Override
public List<com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement> getServiceLevelAgreements() {

    accessController.checkPermission(AccessController.SERVICES,
            FeedServicesAccessControl.ACCESS_SERVICE_LEVEL_AGREEMENTS);
    //find all as a Service account
    List<com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement> agreementsList = this.metadataAccess
            .read(() -> {/*from w w w .j a  va  2  s  . co  m*/
                List<com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement> agreements = feedSlaProvider
                        .findAllAgreements();
                if (agreements != null) {
                    return serviceLevelAgreementTransform.transformFeedServiceLevelAgreements(agreements);
                }

                return new ArrayList<>(0);
            }, MetadataAccess.SERVICE);

    if (accessController.isEntityAccessControlled()) {

        Map<String, com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement> serviceLevelAgreementMap = agreementsList
                .stream()
                .collect(Collectors.toMap(
                        com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement::getId,
                        Function.identity()));
        //filter out those feeds user doesnt have access to
        List<com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement> entityAccessControlledSlas = this.metadataAccess
                .read(() -> {
                    List<com.thinkbiganalytics.metadata.api.sla.FeedServiceLevelAgreement> agreements = feedSlaProvider
                            .findAllAgreements();
                    if (agreements != null) {
                        List<com.thinkbiganalytics.metadata.rest.model.sla.FeedServiceLevelAgreement> serviceLevelAgreements = serviceLevelAgreementTransform
                                .transformFeedServiceLevelAgreements(agreements);
                        return serviceLevelAgreements.stream()
                                .filter(agreement -> serviceLevelAgreementMap.get(agreement.getId())
                                        .getFeedsCount() == agreement.getFeedsCount())
                                .collect(Collectors.toList());
                    }
                    return new ArrayList<>(0);
                });

        return entityAccessControlledSlas;
    } else {
        return agreementsList;
    }

}

From source file:io.syndesis.dao.DeploymentDescriptorTest.java

@Test
public void thereShouldBeNoDuplicateMavenCoordinates() {
    final Map<String, Long> coordinatesWithCount = StreamSupport.stream(deployment.spliterator(), true)
            .filter(data -> "connector".equals(data.get("kind").asText()))
            .flatMap(/*from   ww w .java  2s .  c  o m*/
                    connector -> StreamSupport.stream(connector.get("data").get("actions").spliterator(), true))
            .map(action -> action.get("camelConnectorGAV").asText())
            .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

    final Map<String, Long> multipleCoordinates = coordinatesWithCount.entrySet().stream()
            .filter(e -> e.getValue() > 1).collect(Collectors.toMap(Entry::getKey, Entry::getValue));

    assertThat(multipleCoordinates).as("Expected connector GAV coordinates to be unique").isEmpty();
}

From source file:com.twosigma.beakerx.kernel.magic.command.MavenJarResolver.java

private Map<String, Path> jarsFromRepo() {
    try {//from   www  . j ava 2 s .  co  m
        List<Path> collect = Files.list(Paths.get(pathToMavenRepo)).collect(Collectors.toList());
        return collect.stream().collect(Collectors.toMap(x -> x.getFileName().toString(), x -> x));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:alfio.repository.TicketFieldRepository.java

default Map<String, TicketFieldValue> findAllByTicketIdGroupedByName(int id) {
    return findAllByTicketId(id).stream()
            .collect(Collectors.toMap(TicketFieldValue::getName, Function.identity()));
}