Example usage for java.util Collection stream

List of usage examples for java.util Collection stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:de.metas.ui.web.window.datatypes.json.filters.JSONDocumentFilterParamDescriptor.java

static List<JSONDocumentFilterParamDescriptor> ofCollection(
        final Collection<DocumentFilterParamDescriptor> params, final JSONOptions jsonOpts) {
    return params.stream().map(filter -> of(filter, jsonOpts)).collect(GuavaCollectors.toImmutableList());
}

From source file:com.github.erchu.beancp.MapperExecutorSelector.java

private static <T extends MappingExecutor<?, ?>> T getBestMatchingMappingExecutor(final Class sourceClass,
        final Class destinationClass, final Collection<T> executors, final MapperExecutorMatchMode matchMode) {
    List<T> validMappers = executors.stream().filter(i -> canBeMapped(sourceClass, i.getSourceClass())
            && canBeMapped(destinationClass, i.getDestinationClass())).collect(Collectors.toList());

    if (validMappers.isEmpty()) {
        return null;
    }//from   w  ww  . j a va 2  s  .  c o m

    T mapper;

    if (matchMode == MapperExecutorMatchMode.STRICT_DESTINATION) {
        mapper = firstNonNull(
                firstOrNull(validMappers,
                        (i -> classEqualsOrWrapper(sourceClass, i.getSourceClass())
                                && classEqualsOrWrapper(destinationClass, i.getDestinationClass()))),
                firstOrNull(validMappers,
                        (i -> classEqualsOrWrapper(destinationClass, i.getDestinationClass()))));
    } else {
        mapper = firstNonNull(
                firstOrNull(validMappers,
                        (i -> classEqualsOrWrapper(sourceClass, i.getSourceClass())
                                && classEqualsOrWrapper(destinationClass, i.getDestinationClass()))),
                firstOrNull(validMappers,
                        (i -> classEqualsOrWrapper(destinationClass, i.getDestinationClass()))),
                firstOrNull(validMappers, (i -> classEqualsOrWrapper(sourceClass, i.getSourceClass()))),
                validMappers.get(0));
    }

    return mapper;
}

From source file:mtsar.api.csv.WorkerRankingCSV.java

public static void write(Collection<WorkerRanking> rankings, OutputStream output) throws IOException {
    try (final Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) {
        final Iterable<String[]> iterable = () -> rankings.stream().sorted(ORDER)
                .map(aggregation -> new String[] { Integer.toString(aggregation.getWorker().getId()), // worker_id
                        Double.toString(aggregation.getReputation()) // reputation
                }).iterator();/*w  w  w . j  a  va2s.co m*/

        FORMAT.withHeader(HEADER).print(writer).printRecords(iterable);
    }
}

From source file:com.github.horrorho.inflatabledonkey.cloud.clients.AssetsClient.java

public static List<Assets> assets(HttpClient httpClient, CloudKitty kitty, ProtectionZone zone,
        Collection<Manifest> manifests) throws IOException {

    if (manifests.isEmpty()) {
        return new ArrayList<>();
    }/*from  ww  w .j a  va 2  s. co  m*/

    List<String> manifestIDs = manifests.stream().map(AssetsClient::manifestIDs).flatMap(Collection::stream)
            .collect(Collectors.toList());

    List<CloudKit.RecordRetrieveResponse> responses = kitty.recordRetrieveRequest(httpClient, "_defaultZone",
            manifestIDs);
    logger.info("-- assets() - responses: {}", responses.size());

    // Manifests with multiple counts only return protection info for the first block, as we are passing blocks in
    // order we can reference the previous protection zone.
    // TODO tighten up.
    AtomicReference<ProtectionZone> previous = new AtomicReference<>(zone);

    return responses.stream().filter(CloudKit.RecordRetrieveResponse::hasRecord)
            .map(CloudKit.RecordRetrieveResponse::getRecord).map(r -> assets(r, zone, previous))
            .collect(Collectors.toList());
}

From source file:com.yahoo.bard.webservice.util.Utils.java

/**
 * Given a collection of objects which share the same super class, return the subset of objects that share a common
 * sub class.//from  w w  w .  j  ava  2s .  c o  m
 *
 * @param set  Input set
 * @param <T> Input set type
 * @param type  sub class
 * @param <K> sub class type
 *
 * @return ordered subset of objects that share a common sub class
 */
public static <T, K extends T> LinkedHashSet<K> getSubsetByType(Collection<T> set, Class<K> type) {
    return set.stream().filter(member -> type.isAssignableFrom(member.getClass()))
            .map(StreamUtils.uncheckedCast(type)).collect(Collectors.toCollection(LinkedHashSet::new));
}

From source file:mtsar.api.csv.AnswerAggregationCSV.java

public static void write(Collection<AnswerAggregation> aggregations, OutputStream output) throws IOException {
    try (final Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) {
        final Iterable<String[]> iterable = () -> aggregations.stream().sorted(ORDER)
                .map(aggregation -> new String[] { Integer.toString(aggregation.getTask().getId()), // task_id
                        String.join("|", aggregation.getAnswers()) // answers
                }).iterator();/* w  w w  .  j  a  v  a2s . c om*/

        FORMAT.withHeader(HEADER).print(writer).printRecords(iterable);
    }
}

From source file:com.samsung.sjs.theorysolver.TheorySolver.java

private static <T> Collection<T> without(Collection<T> collection, T element) {
    return collection.stream().filter(e -> !element.equals(e)).collect(Collectors.toList());
}

From source file:com.khartec.waltz.service.data_flow.RatedDataFlowService.java

private static List<RatedDataFlow> prepareResult(Collection<DataFlow> flows,
        Map<String, Map<Long, AuthoritativeSource>> authSourceByTypeThenApp) {
    return flows.stream().map(f -> {
        Rating rating = lookupRatingFn.apply(f, authSourceByTypeThenApp);
        return ImmutableRatedDataFlow.builder().dataFlow(f).rating(rating).build();
    }).collect(Collectors.toList());
}

From source file:uk.co.jassoft.markets.datamodel.story.NamedEntities.java

public static void setEntitySentiment(Collection<NamedEntity> collection, final String name,
        final String sentence, final int sentiment) {
    final String strippedName = name.replaceAll("[^a-zA-Z0-9\\s\\-]", "");

    collection.stream().filter(namedEntity -> namedEntity.getName().equalsIgnoreCase(strippedName))
            .forEach(namedEntity -> {

                namedEntity.getSentiments().stream().filter(s -> s.getSentence().equals(sentence))
                        .forEach(s -> s.setSentiment(sentiment));
            });//from w  ww. j a  va  2s  .  com

}

From source file:mtsar.api.csv.WorkerCSV.java

public static void write(Collection<Worker> workers, OutputStream output) throws IOException {
    try (final Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) {
        final Iterable<String[]> iterable = () -> workers.stream().sorted(ORDER)
                .map(worker -> new String[] { Integer.toString(worker.getId()), // id
                        worker.getStage(), // stage
                        Long.toString(worker.getDateTime().toInstant().getEpochSecond()), // datetime
                        String.join("|", worker.getTags()), // tags
                }).iterator();/*from  ww  w.j a  va 2  s . c  om*/

        FORMAT.withHeader(HEADER).print(writer).printRecords(iterable);
    }
}