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:org.ow2.proactive.workflow_catalog.rest.dto.Variable.java

public static List<Variable> to(
        Collection<? extends org.ow2.proactive.workflow_catalog.rest.entity.Variable> from) {
    return from.stream().map(entity -> new Variable(entity.getKey(), entity.getValue()))
            .collect(Collectors.toList());
}

From source file:io.github.jianzhichun.springboot.starters.swagger2.config.AutoSwagger2Configuration.java

static <T, R> List<R> map2list(Collection<T> collection, Function<? super T, ? extends R> mapper) {
    return collection.stream().map(mapper).collect(Collectors.toList());

}

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

public static List<Asset> assetsFromAssetsList(HttpClient httpClient, CloudKitty kitty, ProtectionZone zone,
        Collection<Assets> assetsList) throws IOException {

    List<String> fileList = assetsList.stream().map(Assets::nonEmptyFiles).flatMap(Collection::stream)
            .collect(Collectors.toList());
    return assets(httpClient, kitty, zone, fileList);

}

From source file:Main.java

public static <T, K, V, M extends Map<K, V>> M toMap(Collection<T> entities, Function<T, K> keyMapper,
        Function<T, V> valueMapper, Supplier<M> supplier) {
    return entities.stream().collect(Collectors.toMap(keyMapper, valueMapper, (a, b) -> b, supplier));
}

From source file:Main.java

/**
 * This method is a shortcut for {@code c.stream()} if c is not {@code null}. If c is {@code null},
 * this method will return an empty stream.
 *
 * @param c   Collection to create a Stream from. If {@code null}, an empty stream will be returned.
 * @param <T> Type of elements in collection.
 * @return Stream created from collection {@code c}.
 *///from  w w  w. ja  va 2 s  . c  o m
public static <T> Stream<T> $(Collection<T> c) {
    if (c == null) {
        return Stream.empty();
    }
    // else
    return c.stream();
}

From source file:ch.ivyteam.ivy.maven.util.ClasspathJar.java

private static List<String> getClassPathUris(Collection<File> classpathEntries) {
    return classpathEntries.stream().map(file -> file.toURI().toASCIIString()).collect(Collectors.toList());
}

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

public static List<Asset> assets(HttpClient httpClient, CloudKitty kitty, ProtectionZone zone,
        Collection<String> fileList) throws IOException {

    List<String> nonEmptyFileList = fileList.stream().filter(Assets::isNonEmpty).collect(Collectors.toList());
    logger.debug("-- assets() - non-empty file list size: {}", nonEmptyFileList.size());

    if (nonEmptyFileList.isEmpty()) {
        return new ArrayList<>();
    }// w  w  w  . j a v  a 2  s.  com

    List<CloudKit.RecordRetrieveResponse> responses = kitty.recordRetrieveRequest(httpClient, "_defaultZone",
            nonEmptyFileList);

    return responses.stream().filter(CloudKit.RecordRetrieveResponse::hasRecord)
            .map(CloudKit.RecordRetrieveResponse::getRecord).map(r -> asset(r, zone))
            .filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
}

From source file:Main.java

public static <T> boolean hasCycle(Collection<T> vertices, Function<T, Collection<T>> neighborExtractor) {
    Map<T, Collection<T>> parents = vertices.stream().collect(toMap(identity(), v -> new ArrayList<T>()));
    vertices.forEach(//from  ww w .  jav  a 2 s .c o  m
            v -> nullSafeCollection(neighborExtractor.apply(v)).forEach(child -> parents.get(child).add(v)));

    Set<T> roots = vertices.stream().filter(v -> parents.get(v).isEmpty()).collect(Collectors.toSet());

    while (!roots.isEmpty()) {
        T root = roots.iterator().next();
        roots.remove(root);
        parents.remove(root);

        nullSafeCollection(neighborExtractor.apply(root)).forEach(child -> {
            parents.get(child).remove(root);
            if (parents.get(child).isEmpty()) {
                roots.add(child);
            }
        });

    }

    return !parents.isEmpty();
}

From source file:io.yields.math.concepts.operator.Smoothness.java

public static List<Tuple> normalize(Collection<Tuple> tuples) {
    DoubleSummaryStatistics statsForX = tuples.stream()
            .collect(Collectors.summarizingDouble(tuple -> tuple.getX()));
    DoubleSummaryStatistics statsForY = tuples.stream()
            .collect(Collectors.summarizingDouble(tuple -> tuple.getY()));
    double minX = statsForX.getMin();
    double maxX = statsForX.getMax();
    double minY = statsForY.getMin();
    double maxY = statsForY.getMax();
    return tuples.stream().map(tuple -> {
        double x = (tuple.getX() - minX) / (maxX - minX);
        double y = (tuple.getY() - minY) / (maxY - minY);
        return new Tuple(x, y);
    }).collect(Collectors.toList());
}

From source file:com.thoughtworks.go.config.CaseInsensitiveString.java

public static List<String> toStringList(Collection<CaseInsensitiveString> strings) {
    return toStringList(strings.stream());
}