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:Main.java

public static String join(Collection<?> objects, String delimiter, String prefix, String suffix) {
    return objects.stream().map(String::valueOf).collect(joining(delimiter, prefix, suffix));
}

From source file:Main.java

public static <T, K, V> HashMap<K, HashSet<V>> group(Collection<T> entities, Function<T, K> keyMapper,
        Function<T, V> valueMapper) {
    return entities.stream().collect(Collectors.groupingBy(keyMapper, HashMap::new,
            Collectors.mapping(valueMapper, Collectors.toCollection(HashSet::new))));
}

From source file:Main.java

public static <T> Set<T> conjunctCollectionsToSet(Collection<T> list1, Collection<T> list2) {
    Set<T> set = new HashSet<>(list2);
    return list1.stream().filter(set::contains).collect(Collectors.toSet());
}

From source file:com.github.horrorho.inflatabledonkey.cloudkitty.operations.ZoneRetrieveRequestOperations.java

static List<RequestOperation> operations(Collection<String> zones, String cloudKitUserId) {
    return zones.stream().map(u -> operation(u, cloudKitUserId)).collect(Collectors.toList());
}

From source file:Main.java

public static <T> List<T> conjunctCollections(Collection<T> list1, Collection<T> list2) {
    Set<T> set = new HashSet<>(list2);
    return list1.stream().filter(set::contains).collect(Collectors.toList());
}

From source file:com.github.horrorho.inflatabledonkey.cloudkitty.operations.RecordRetrieveRequestOperations.java

static List<RequestOperation> operations(String zone, Collection<String> recordNames, String cloudKitUserId) {
    return recordNames.stream().map(u -> operation(zone, u, cloudKitUserId)).collect(Collectors.toList());
}

From source file:Main.java

public static <T> Set<T> conjunctCollectionsToSet(Collection<T> list1, Collection<T> list2) {
    Set<T> set = new HashSet<>(list2);
    return list1.stream().filter(set::contains).collect(toSet());
}

From source file:Main.java

public static <T> List<T> conjunctCollections(Collection<T> list1, Collection<T> list2) {
    Set<T> set = new HashSet<>(list2);
    return list1.stream().filter(set::contains).collect(toList());
}

From source file:Main.java

/**
 * Transform the source collection using the mapping function to convert the elements to the output type. The result
 * is written to a set.//from w w w  .j  av  a 2s  .c om
 *
 * @param <T>
 *            the source type type
 * @param <R>
 *            the result type
 * @param source
 *            the source
 * @param mapping
 *            the mapping used for the value transformation
 * @return the sets the
 */
public static <T, R> Set<R> transformToSet(Collection<T> source, Function<T, R> mapping) {
    return source.stream().map(mapping)
            .collect(Collectors.toCollection(() -> createLinkedHashSet(source.size())));
}

From source file:Main.java

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