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:se.uu.it.cs.recsys.ruleminer.api.RuleMiner.java

/**
 *
 * @param targets//from www  .  j  a va 2s . c o m
 * @param threshold
 * @return pairs of (rule, support)
 */
@Cacheable("FPPatterns")
public Map<Set<Integer>, Integer> getPatterns(Set<Integer> targets, Integer threshold) {

    Map<Set<Integer>, Integer> allRules = getPatterns(threshold);

    return allRules.entrySet().stream().filter(intertectWithTargets(targets))
            .filter(entry -> entry.getKey().size() > 1)
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

From source file:io.syndesis.credential.CredentialProviderRegistry.java

CredentialProviderRegistry(final DataManager dataManager) {
    this.dataManager = dataManager;

    credentialProviderFactories = SpringFactoriesLoader
            .loadFactories(CredentialProviderFactory.class, ClassUtils.getDefaultClassLoader()).stream()
            .collect(Collectors.toMap(CredentialProviderFactory::id, Function.identity()));
}

From source file:org.dataconservancy.packaging.tool.integration.PackageInitializer.java

public PackageState initialize(URI profile) {
    try {/*from w ww. ja v a  2 s  .  c o  m*/
        Node tree = ipmService
                .createTreeFromFileSystem(Paths.get(this.getClass().getResource("/TestContent/foo").toURI())
                        .getParent().resolve("Parent_Dir"));

        Map<URI, DomainProfile> profiles = profileStore.getPrimaryDomainProfiles().stream()
                .collect(Collectors.toMap(DomainProfile::getIdentifier, Function.identity()));

        Model model = ModelFactory.createDefaultModel();

        DomainProfileService profileService = profileFactory.getProfileService(model);

        profileService.assignNodeTypes(profiles.get(profile), tree);

        PackageState state = new PackageState();

        state.setDomainObjectRDF(model);
        state.setPackageTree(ipm2rdf.transformToRDF(tree));
        state.setUserSpecifiedProperties(new HashMap<>());
        return state;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.teradata.tempto.internal.configuration.ConfigurationVariableResolver.java

private Map<String, Object> resolveVariables(Configuration configuration, StrSubstitutor strSubstitutor) {
    return configuration.listKeyPrefixes(1).stream()
            .map(prefix -> resolveConfigurationEntry(configuration, prefix, strSubstitutor))
            .collect(Collectors.toMap(entry -> entry.getLeft(), entry -> entry.getRight()));
}

From source file:newcontroller.handler.impl.DefaultRequest.java

@Override
public Map<String, List<String>> params() {
    return this.request.getParameterMap().entrySet().stream()
            .collect(Collectors.toMap(Map.Entry::getKey, x -> Arrays.asList(x.getValue())));
}

From source file:com.netflix.spinnaker.igor.config.GitlabCiConfig.java

@Bean
public Map<String, GitlabCiService> gitlabCiMasters(BuildMasters buildMasters,
        final IgorConfigurationProperties igorConfigurationProperties, GitlabCiProperties gitlabCiProperties,
        ObjectMapper objectMapper) {//from  w  ww .j a v  a 2  s. c  o m
    log.info("creating gitlabCiMasters");
    Map<String, GitlabCiService> gitlabCiMasters = gitlabCiProperties.getMasters().stream()
            .collect(Collectors.toMap(gitlabCiHost -> "gitlab-ci-" + gitlabCiHost.getName(),
                    gitlabCiHost -> gitlabCiService(igorConfigurationProperties, gitlabCiHost, objectMapper)));
    buildMasters.getMap().putAll(gitlabCiMasters);
    return gitlabCiMasters;
}

From source file:mtsar.processors.meta.ZenCrowd.java

@Nonnull
@Override/*from  www . j  ava  2s .  c o m*/
public Map<Integer, AnswerAggregation> aggregate(@Nonnull Collection<Task> tasks) {
    requireNonNull(stage, "the stage provider should not provide null");
    if (tasks.isEmpty())
        return Collections.emptyMap();
    final Map<Integer, Task> taskIds = tasks.stream()
            .collect(Collectors.toMap(Task::getId, Function.identity()));
    final Models.ZenModel<Integer, Integer, String> zenModel = compute(stage, answerDAO, getTaskMap())
            .getZenModel();
    final ZenCrowdEM<Integer, Integer, String> zenCrowd = new ZenCrowdEM<>(zenModel);
    zenCrowd.computeLabelEstimates();
    final Map<Integer, AnswerAggregation> aggregations = zenCrowd.getCurrentModel().getCombinedEstLabels()
            .entrySet().stream().filter(entry -> taskIds.containsKey(entry.getKey()))
            .collect(Collectors.toMap(Map.Entry::getKey, entry -> new AnswerAggregation.Builder()
                    .setTask(taskIds.get(entry.getKey())).addAnswers(entry.getValue().getFirst()).build()));
    return aggregations;
}

From source file:org.ow2.proactive.connector.iaas.cache.InfrastructureCache.java

private Map<String, Infrastructure> cloneSupportedInfrastructures() {
    return supportedInfrastructures.entrySet().stream()
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

From source file:delfos.dataset.generated.modifieddatasets.pseudouser.PseudoUserRatingsDataset.java

public PseudoUserRatingsDataset(DatasetLoader<RatingType> originalDatasetLoader,
        Map<User, Map<Item, RatingType>> pseudoUsersRatings) {

    this.originalDatasetLoader = originalDatasetLoader;
    this.pseudoUsersRatings = pseudoUsersRatings;

    pseudoUsersById = pseudoUsersRatings.keySet().stream()
            .collect(Collectors.toMap(user -> user.getId(), user -> user));
}

From source file:org.openlmis.fulfillment.service.ShipmentService.java

/**
 * Saves the given shipment to database. Also related Proof Of Delivery will be created.
 *//*from   ww w .j a  v  a  2 s.  co m*/
public Shipment save(final Shipment shipment) {
    Shipment saved = shipmentRepository.save(shipment);

    Set<UUID> orderableIds = saved.getLineItems().stream().map(ShipmentLineItem::getOrderableId)
            .collect(Collectors.toSet());

    Map<UUID, Boolean> useVvm = orderableReferenceDataService.findByIds(orderableIds).stream()
            .collect(Collectors.toMap(BaseDto::getId, OrderableDto::useVvm));

    ProofOfDelivery proofOfDelivery = ProofOfDelivery.newInstance(saved, useVvm);
    proofOfDeliveryRepository.save(proofOfDelivery);

    return saved;
}