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:com.nike.cerberus.service.CloudFormationService.java

/**
 * Returns the current status of the named stack.
 *
 * @param stackId Stack name./*from ww  w  .j a  v  a 2 s  . c  om*/
 * @return Stack outputs data.
 */
public Map<String, String> getStackOutputs(final String stackId) {
    final DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackId);
    final DescribeStacksResult result = cloudFormationClient.describeStacks(request);
    final Map<String, String> outputs = Maps.newHashMap();

    if (result.getStacks().size() > 0) {
        outputs.putAll(result.getStacks().get(0).getOutputs().stream()
                .collect(Collectors.toMap(Output::getOutputKey, Output::getOutputValue)));

    }

    return outputs;
}

From source file:com.ikanow.aleph2.distributed_services.utils.KafkaUtils.java

/** Returns the map of kafka properties
 * @return//from  w  w w. java 2 s .  c  om
 */
public static Map<String, String> getProperties() {
    return kafka_properties.entrySet().stream().collect(Collectors.toMap(o -> o.toString(),
            o -> Optional.ofNullable(o).map(oo -> oo.toString()).orElse(null)));
}

From source file:de.perdian.apps.tagtiger.fx.handlers.batchupdate.UpdateFileNamesFromTagsActionEventHandler.java

private void computeNewFileNames(List<UpdateFileNamesFromTagsItem> items, String fileNamePattern) {
    for (UpdateFileNamesFromTagsItem item : items) {

        Map<String, String> replacementValues = Arrays.stream(UpdateFileNamesPlaceholder.values())
                .collect(Collectors.toMap(p -> p.getPlaceholder(), p -> p.resolveValue(item.getFile())));

        StrSubstitutor substitutor = new StrSubstitutor(replacementValues);
        String substitutionEvaluationResult = substitutor.replace(fileNamePattern);
        String substitutionSanitizedResult = this.sanitizeFileName(substitutionEvaluationResult).trim();

        if (!Objects.equals(substitutionSanitizedResult, item.getNewFileName().getValue())) {
            item.getNewFileName().setValue(substitutionSanitizedResult);
        }/*from   www.j  av a 2s .c  o  m*/

    }
}

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

private Map<UUID, OrderableDto> getOrderables(Set<UUID> orderableUuids) {
    return orderableReferenceDataService.findByIds(orderableUuids).stream()
            .collect(Collectors.toMap(OrderableDto::getId, orderable -> orderable));
}

From source file:nu.yona.server.goals.service.ActivityCategoryService.java

private void addOrUpdateNewActivityCategories(Set<ActivityCategoryDto> activityCategoryDtos,
        Set<ActivityCategory> activityCategoriesInRepository) {
    Map<UUID, ActivityCategory> activityCategoriesInRepositoryMap = activityCategoriesInRepository.stream()
            .collect(Collectors.toMap(ActivityCategory::getId, ac -> ac));

    activityCategoryDtos.stream()//from   w  w w .  ja v  a 2s  .  c om
            .forEach(a -> addOrUpdateNewActivityCategory(a, activityCategoriesInRepositoryMap));
}

From source file:com.epam.catgenome.manager.vcf.VcfManager.java

/**
 * Registers a VCF file in the system to make it available to browse. Creates Tribble/Tabix index if absent
 * and a feature index to allow fast search for variations
 *
 * @param request a request for file registration, containing path to file, reference ID and optional parameters:
 *                path to index file and vcf file name to save in the system
 * @return a {@code VcfFile} that was registered
 *///from  ww  w .  j av a 2s .co m
public VcfFile registerVcfFile(FeatureIndexedFileRegistrationRequest request) {
    final String requestPath = request.getPath();
    Assert.isTrue(StringUtils.isNotBlank(requestPath), getMessage(MessagesConstants.ERROR_NULL_PARAM, "path"));
    Assert.notNull(request.getReferenceId(), getMessage(MessagesConstants.ERROR_NULL_PARAM, "referenceId"));

    VcfFile vcfFile;
    Reference reference = referenceGenomeManager.loadReferenceGenome(request.getReferenceId());
    Map<String, Chromosome> chromosomeMap = reference.getChromosomes().stream()
            .collect(Collectors.toMap(BaseEntity::getName, chromosome -> chromosome));
    if (request.getType() == null) {
        request.setType(BiologicalDataItemResourceType.FILE);
    }
    switch (request.getType()) {
    case GA4GH:
        vcfFile = getVcfFileFromGA4GH(request, requestPath);
        break;
    case FILE:
        vcfFile = createVcfFromFile(request, chromosomeMap, reference, request.isDoIndex());
        break;
    case DOWNLOAD:
        vcfFile = downloadVcfFile(request, requestPath, chromosomeMap, reference, request.isDoIndex());
        break;
    case URL:
        vcfFile = createVcfFromUrl(request, chromosomeMap, reference);
        break;
    default:
        throw new IllegalArgumentException(getMessage(MessagesConstants.ERROR_INVALID_PARAM));
    }
    return vcfFile;
}

From source file:com.vaadin.framework7.samples.SpringCrudIT.java

private void checkCategories(WebElement form, Product product) {
    WebElement categories = form.findElement(By.className("v-select-optiongroup"));
    WebElement captionElement = categories.findElement(By.xpath("..")).findElement(By.className("v-caption"));
    Assert.assertEquals("Categories", captionElement.getText());

    List<WebElement> checkboxes = categories.findElements(By.className("v-checkbox"));
    Set<String> cats = checkboxes.stream().map(WebElement::getText).collect(Collectors.toSet());
    Set<String> allCats = dataService.getAllCategories().stream().map(Category::getName)
            .collect(Collectors.toSet());
    Assert.assertEquals(allCats, cats);//from   w  w w  .j  a  v  a  2  s  . c om
    Map<String, Category> productCategories = product.getCategory().stream()
            .collect(Collectors.toMap(Category::getName, Function.identity()));

    checkboxes.forEach(checkbox -> checkCategory(checkbox, productCategories));
}

From source file:com.marsspiders.ukwa.controllers.CollectionController.java

private List<CollectionDTO> generateRootCollectionDTOs(Locale locale) {
    Map<String, CollectionDTO> rootCollections = searchService.fetchRootCollections().getResponseBody()
            .getDocuments().stream().collect(Collectors.toMap(CollectionInfo::getId,
                    collection -> toCollectionDTO(collection, true, locale)));

    Set<String> parentCollectionIds = rootCollections.keySet();

    searchService.fetchChildCollections(parentCollectionIds, TYPE_COLLECTION, 1000, 0).getResponseBody()
            .getDocuments().stream().forEach(subCollection -> {
                String parentId = subCollection.getParentId();

                CollectionDTO parentCollectionDto = rootCollections.get(parentId);
                if (parentCollectionDto.getSubCollections() == null) {
                    parentCollectionDto.setSubCollections(new ArrayList<>());
                }//from   ww  w  .ja v a 2  s  .c  o  m

                CollectionDTO subCollectionDTO = toCollectionDTO(subCollection, true, locale);
                parentCollectionDto.getSubCollections().add(subCollectionDTO);

            });

    ArrayList<CollectionDTO> sortedCollectionDTOs = new ArrayList<>(rootCollections.values());
    Collections.sort(sortedCollectionDTOs, (c1, c2) -> c1.getName().compareTo(c2.getName()));

    return sortedCollectionDTOs;
}

From source file:onl.area51.httpd.action.Request.java

static Request create(HttpRequest req, HttpResponse resp, HttpContext ctx) {
    return new Request() {
        Response response;//from   w ww .j a va  2s  .  com
        URI uri;
        Map<String, String> params;

        private String decode(String s) {
            try {
                return URLDecoder.decode(s, "UTF-8");
            } catch (UnsupportedEncodingException ex) {
                return s;
            }
        }

        private void decodeParams() throws IOException {
            if (uri == null) {
                try {
                    uri = new URI(req.getRequestLine().getUri());

                    String q = uri.getQuery();
                    params = q == null || q.isEmpty() ? Collections.emptyMap()
                            : Stream.of(q.split("&")).map(s -> s.split("=", 2)).collect(Collectors
                                    .toMap(p -> decode(p[0]), p -> p.length == 1 ? "" : decode(p[1])));
                } catch (URISyntaxException ex) {
                    throw new IOException(ex);
                }
            }
        }

        @Override
        public URI getURI() throws IOException {
            decodeParams();
            return uri;
        }

        @Override
        public Collection<String> getParamNames() throws IOException {
            decodeParams();
            return params.keySet();
        }

        @Override
        public String getParam(String n) throws IOException {
            decodeParams();
            return params.get(n);
        }

        @Override
        public Response getResponse() {
            if (response == null) {
                response = Response.create(this);
            }
            return response;
        }

        @Override
        public boolean isResponsePresent() {
            return response != null;
        }

        @Override
        public HttpRequest getHttpRequest() {
            return req;
        }

        @Override
        public HttpResponse getHttpResponse() {
            return resp;
        }

        @Override
        public HttpContext getHttpContext() {
            return ctx;
        }
    };
}

From source file:alfio.repository.TicketFieldRepository.java

default Map<Integer, TicketFieldDescription> findTranslationsFor(Locale locale, int eventId) {
    return findDescriptions(eventId, locale.getLanguage()).stream().collect(
            Collectors.toMap(TicketFieldDescription::getTicketFieldConfigurationId, Function.identity()));
}