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:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java

public static List<String> addValues(Collection<Pair<Double, List<String>>> input) {
    return range(0, input.stream().findAny().get().getRight().size()).boxed().map(i -> {
        return input.parallelStream().map(pair -> multiplyValues(asMap(pair.getRight().get(i)), pair.getLeft()))
                .reduce(new HashMap<>(), (map1, map2) -> sum(map1, map2));
    }).map(LibSVMUtils::asString).collect(toList());
}

From source file:com.ebay.myriad.scheduler.SchedulerUtils.java

public static boolean isUniqueHostname(Offer offer, Collection<NodeTask> tasks) {
    Preconditions.checkArgument(offer != null);
    String offerHostname = offer.getHostname();

    if (CollectionUtils.isEmpty(tasks)) {
        return true;
    }/*www  . ja v  a 2  s  .c om*/

    boolean uniqueHostname = tasks.stream().filter(task -> offerHostname.equalsIgnoreCase(task.getHostname()))
            .count() == 0;
    LOGGER.info("Offer's hostname {} is unique: {}", offerHostname, uniqueHostname);
    return uniqueHostname;
}

From source file:com.spotify.heroic.filter.AndFilter.java

static SortedSet<Filter> flatten(final Collection<Filter> filters) {
    final SortedSet<Filter> result = new TreeSet<>();

    filters.stream().flatMap(f -> f.optimize().visit(new Filter.Visitor<Stream<Filter>>() {
        @Override/*ww  w .j a v  a2 s .c om*/
        public Stream<Filter> visitAnd(final AndFilter and) {
            return and.terms().stream().map(Filter::optimize);
        }

        @Override
        public Stream<Filter> visitNot(final NotFilter not) {
            // check for De Morgan's
            return not.getFilter().visit(new Filter.Visitor<Stream<Filter>>() {
                @Override
                public Stream<Filter> visitOr(final OrFilter or) {
                    return or.terms().stream().map(f -> NotFilter.of(f).optimize());
                }

                @Override
                public Stream<Filter> defaultAction(final Filter filter) {
                    return Stream.of(not.optimize());
                }
            });
        }

        @Override
        public Stream<Filter> defaultAction(final Filter filter) {
            return Stream.of(filter.optimize());
        }
    })).forEach(result::add);

    return result;
}

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

public static List<JSONDocumentFilterDescriptor> ofCollection(
        @Nullable final Collection<DocumentFilterDescriptor> filters, final JSONOptions jsonOpts) {
    if (filters == null || filters.isEmpty()) {
        return ImmutableList.of();
    }//from   w  ww . j a v a  2  s  . co  m

    return filters.stream().map(filter -> new JSONDocumentFilterDescriptor(filter, jsonOpts))
            .collect(GuavaCollectors.toImmutableList());
}

From source file:com.vmware.admiral.compute.container.volume.VolumeUtil.java

private static <T extends ResourceState> Map<String, T> filterDescriptions(Class<T> clazz,
        Collection<ComponentDescription> componentDescriptions) {

    return componentDescriptions.stream().filter(cd -> clazz.isInstance(cd.getServiceDocument()))
            .map(cd -> clazz.cast(cd.getServiceDocument())).collect(Collectors.toMap(c -> c.name, c -> c));
}

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

static List<JSONDocumentLayoutTab> ofList(final Collection<DocumentLayoutDetailDescriptor> details,
        final JSONOptions jsonOpts) {
    final Collection<DocumentFilterDescriptor> filters = null;
    return details.stream().map(detail -> of(detail, filters, jsonOpts))
            .filter(jsonDetail -> jsonDetail.hasElements()).collect(GuavaCollectors.toImmutableList());
}

From source file:co.runrightfast.vertx.core.protobuf.MessageConversions.java

static JsonArray toJsonArray(final Collection<RunRightFastVerticleDeployment> deployments) {
    if (deployments == null) {
        return JsonUtils.EMPTY_ARRAY;
    }//from w  w w. j  a  v a2s .c o m

    final JsonArrayBuilder jsonArray = Json.createArrayBuilder();
    deployments.stream().forEach(deployment -> jsonArray.add(deployment.toJson()));
    return jsonArray.build();
}

From source file:gobblin.source.extractor.extract.kafka.ConfigStoreUtils.java

/**
 * Will return the list of URIs given which are importing tag {@param tagUri}
 *///from  w w w  .j  av a 2  s .  co  m
public static Collection<URI> getTopicsURIFromConfigStore(ConfigClient configClient, Path tagUri,
        String filterString, Optional<Config> runtimeConfig) {
    try {
        Collection<URI> importedBy = configClient.getImportedBy(new URI(tagUri.toString()), true,
                runtimeConfig);
        return importedBy.stream().filter((URI u) -> u.toString().contains(filterString))
                .collect(Collectors.toList());
    } catch (URISyntaxException | ConfigStoreFactoryDoesNotExistsException | ConfigStoreCreationException e) {
        throw new Error(e);
    }
}

From source file:de.bund.bfr.knime.pmmlite.core.PmmUtils.java

public static Set<String> getConditions(Collection<TimeSeries> data) {
    return data.stream().map(s -> s.getConditions()).flatMap(List::stream).map(c -> c.getName())
            .collect(Collectors.toCollection(LinkedHashSet::new));
}

From source file:de.bund.bfr.knime.pmmlite.core.PmmUtils.java

public static Set<String> getParameters(Collection<? extends Model> models) {
    return models.stream().map(m -> m.getParamValues().keySet()).flatMap(Set::stream)
            .collect(Collectors.toCollection(LinkedHashSet::new));
}