Example usage for java.util List stream

List of usage examples for java.util List stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:lumbermill.elasticsearch.ElasticSearchBulkResponseEvent.java

private static ObjectNode buildPostponedJsonResponse(List<JsonEvent> events) {
    ObjectNode node = Json.OBJECT_MAPPER.createObjectNode().put("errors", false).put("took", 1L);
    node.putArray("items").addAll(events.stream().map(ElasticSearchBulkResponseEvent::toPostponsedEvent)
            .collect(Collectors.toList()));
    System.out.println("Response built: " + new JsonEvent(node).toString(true));
    return node;//from ww w. j a  v a2  s.c om

}

From source file:com.pinterest.rocksplicator.controller.config.ConfigParserTest.java

public static Optional<HostBean> findHost(List<HostBean> hosts, String ip, int port) {
    return hosts.stream().filter(h -> h.getIp().equals(ip) && h.getPort() == port).findAny();
}

From source file:de.tynne.benchmarksuite.Main.java

/** Returns a producer for all benchmarks in the named suites.
 *//*from  ww w  . j  av  a2 s.  c o  m*/
private static BenchmarkProducer findAllByName(List<String> suiteNames,
        Map<BenchmarkSuite, BenchmarkProducer> suites) {
    List<BenchmarkProducer> benchmarkProducers = suiteNames.stream().map(s -> findByName(s, suites))
            .filter(bp -> bp.isPresent()).map(o -> o.get()).collect(Collectors.toList());

    return () -> {
        List<Benchmark> result = new ArrayList<>();
        benchmarkProducers.forEach(bp -> {
            result.addAll(bp.get());
        });
        return result;
    };
}

From source file:io.wcm.caconfig.extensions.references.impl.ConfigurationReferenceProvider.java

/**
 * Build reference display name from path with:
 * - translating configuration names to labels
 * - omitting configuration bucket names
 * - insert additional spaces so long paths may wrap on multiple lines
 *//*from   w ww. j  av  a2  s.  c  om*/
private static String getReferenceName(Page configPage,
        Map<String, ConfigurationMetadata> configurationMetadatas, Set<String> configurationBuckets) {
    List<String> pathParts = Arrays.asList(StringUtils.split(configPage.getPath(), "/"));
    return pathParts.stream().filter(name -> !configurationBuckets.contains(name)).map(name -> {
        ConfigurationMetadata configMetadata = configurationMetadatas.get(name);
        if (configMetadata != null && configMetadata.getLabel() != null) {
            return configMetadata.getLabel();
        } else {
            return name;
        }
    }).collect(Collectors.joining(" / "));
}

From source file:org.mytms.common.dao.querydsl.QSort.java

/**
 * Converts the given {@link OrderSpecifier}s into a list of {@link Order}s.
 * /*from   ww w.  ja v  a2s  .co m*/
 * @param orderSpecifiers must not be {@literal null} or empty.
 * @return
 */
private static List<Order> toOrders(List<OrderSpecifier<?>> orderSpecifiers) {

    Assert.notNull(orderSpecifiers, "Order specifiers must not be null!");

    return orderSpecifiers.stream().map(QSort::toOrder).collect(Collectors.toList());
}

From source file:net.hamnaberg.json.Property.java

public static Property arrayObject(String name, Optional<String> prompt, List<Object> list) {
    return array(name, prompt,
            list.stream().map(ValueFactory::createOptionalValue)
                    .flatMap(optionalValue -> optionalValue.map(Stream::of).orElseGet(Stream::empty))
                    .collect(Collectors.toList()));
}

From source file:com.pinterest.rocksplicator.controller.config.ConfigParserTest.java

public static Optional<SegmentBean> findSegment(List<SegmentBean> segments, String segmentName) {
    return segments.stream().filter(s -> s.getName().equals(segmentName)).findAny();
}

From source file:com.netflix.spinnaker.clouddriver.google.controllers.GoogleNamedImageLookupController.java

private static Map<String, String> extractTagFilters(HttpServletRequest httpServletRequest) {
    List<String> parameterNames = Collections.list(httpServletRequest.getParameterNames());

    return parameterNames.stream().filter(Objects::nonNull)
            .filter(parameter -> parameter.toLowerCase().startsWith("tag:"))
            .collect(Collectors.toMap(tagParameter -> tagParameter.replaceAll("tag:", "").toLowerCase(),
                    httpServletRequest::getParameter, (a, b) -> b));
}

From source file:alfio.controller.support.TicketDecorator.java

public static List<TicketDecorator> decorate(List<Ticket> tickets, boolean freeCancellationEnabled,
        Function<Ticket, Boolean> categoryEvaluator,
        Function<Ticket, List<Pair<TicketFieldConfigurationAndDescription, String>>> fieldsLoader) {
    return tickets.stream().map(t -> new TicketDecorator(t, freeCancellationEnabled, categoryEvaluator.apply(t),
            fieldsLoader.apply(t))).collect(Collectors.toList());
}

From source file:it.reply.orchestrator.controller.ControllerTestUtils.java

public static List<Deployment> createDeployments(int total, boolean sorted) {
    List<Deployment> deployments = Lists.newArrayList();
    for (int i = 0; i < total; ++i) {
        deployments.add(createDeployment());
    }// w  w w . j  a v a2s  .  co m
    if (sorted) {
        deployments.stream().sorted(new Comparator<Deployment>() {

            @Override
            public int compare(Deployment o1, Deployment o2) {
                return o1.getCreated().compareTo(o2.getCreated());
            }
        }).collect(Collectors.toList());
    }
    return deployments;
}