Java Code Examples for java.util.stream.Collectors#toList()

The following examples show how to use java.util.stream.Collectors#toList() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testParSquaresResults() throws Exception {
    int count = 15;
    var keys = new ArrayList<>(demos.keySet());
    var demo1 = demos.get(keys.get(0));
    var demo2 = demos.get(keys.get(1));
    var demo3 = demos.get(keys.get(2));
    var join = Collectors.toList();
    var r1 = demo1.doParallelSquaresAsync(count).get().stream().sorted().collect(join);
    var r2 = demo2.doParallelSquaresAsync(count).get().stream().sorted().collect(join);
    var r3 = demo3.doParallelSquaresAsync(count).get().stream().sorted().collect(join);
    assertEquals(demo1.getClass() + " != " + demo2.getClass(), r1, r2);
    assertEquals(demo3.getClass() + " != " + demo2.getClass(), r3, r2);
}
 
Example 2
Source Project: cyclops   File: SpoutsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCollector(){
    Collector<Integer, ?, List<Integer>> list = Collectors.toList();
    List<Integer> res= null;
    res =Stream.of(1,2,3)
                .map(i->i+2)
                .collect(list);
    System.out.println("res " + res);
 //   Stream.of(1,2,3).collect((Supplier)list.supplier(),list.accumulator(),list.combiner());
}
 
Example 3
/**
 * Based on the query options, returns a collector that puts Datastore query results
 * in a correct form.
 *
 * @return collector
 */
private Collector<?, ?, ?> getResultsCollector() {
	Collector<?, ?, ?> collector  = Collectors.toList();
	if (isCountingQuery && !PartTreeDatastoreQuery.this.tree.isDelete()) {
		collector = Collectors.counting();
	}
	else if (PartTreeDatastoreQuery.this.tree.isExistsProjection()) {
		collector = Collectors.collectingAndThen(Collectors.counting(), (count) -> count > 0);
	}
	return collector;
}
 
Example 4
Source Project: attic-polygene-java   File: Annotations.java    License: Apache License 2.0 5 votes vote down vote up
public static List<Annotation> findAccessorAndTypeAnnotationsIn(AccessibleObject accessor) {
    Stream<Annotation> stream = Stream.concat(
            Arrays.stream(accessor.getAnnotations()),
            interfacesOf(typeOf(accessor)).flatMap(ANNOTATIONS_OF)
    );
    Collector<Annotation, ?, List<Annotation>> collector = Collectors.toList();
    return stream.collect(collector);
}
 
Example 5
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 6
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 7
@Test
public void collect() {
    Collector collector = Collectors.toList();
    Graph graph = graphFor(builder().collect(collector));
    assertSame(getAddedStage(Stage.Collect.class, graph).getCollector(), collector);
}
 
Example 8
Source Project: cyclops   File: Vector.java    License: Apache License 2.0 4 votes vote down vote up
static <T> Collector<T, List<T>, Vector<T>> collector() {
    Collector<T, ?, List<T>> c  = Collectors.toList();
    return Collectors.<T, List<T>, Iterable<T>,Vector<T>>collectingAndThen((Collector)c,Vector::fromIterable);
}
 
Example 9
Source Project: cyclops   File: LazyString.java    License: Apache License 2.0 4 votes vote down vote up
static Collector<Character, List<Character>, LazyString> collector() {
    Collector<Character, ?, List<Character>> c  = Collectors.toList();
    return Collectors.<Character, List<Character>, Iterable<Character>,LazyString>collectingAndThen((Collector)c,LazyString::fromIterable);
}
 
Example 10
Source Project: cyclops   File: BankersQueue.java    License: Apache License 2.0 4 votes vote down vote up
static <T> Collector<T, List<T>, BankersQueue<T>> collector() {
    Collector<T, ?, List<T>> c  = Collectors.toList();
    return Collectors.<T, List<T>, Iterable<T>,BankersQueue<T>>collectingAndThen((Collector)c,BankersQueue::fromIterable);
}
 
Example 11
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 12
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 13
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 14
Source Project: cyclops   File: LazySeq.java    License: Apache License 2.0 4 votes vote down vote up
static <T> Collector<T, List<T>, LazySeq<T>> collector() {
    Collector<T, ?, List<T>> c  = Collectors.toList();
    return Collectors.<T, List<T>, Iterable<T>,LazySeq<T>>collectingAndThen((Collector)c,LazySeq::fromIterable);
}
 
Example 15
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 16
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 17
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 18
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 19
Source Project: cyclops   File: Seq.java    License: Apache License 2.0 4 votes vote down vote up
static <T> Collector<T, List<T>, Seq<T>> collector() {
    Collector<T, ?, List<T>> c  = Collectors.toList();
    return Collectors.<T, List<T>, Iterable<T>,Seq<T>>collectingAndThen((Collector)c,Seq::fromIterable);
}
 
Example 20
Source Project: essentials4j   File: To.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Returns a {@code Collector} that accumulates the input elements into a new {@code List}.
 * <p>
 * A shortcut for: {@code Collectors.toList()}.
 *
 * @param <T> the type of the output list elements
 * @return a new collector that accumulates the input elements into a new {@code List}
 * @see Collectors#toList()
 */
public static <T> Collector<T, ?, List<T>> list() {
	return Collectors.toList();
}