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

The following examples show how to use java.util.stream.Collectors#toList() . 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
Source File: PerformanceTest.java    From reactive-streams-in-java with Apache License 2.0 5 votes vote down vote up
@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 File: Annotations.java    From attic-polygene-java with 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 3
Source File: SpoutsTest.java    From cyclops with 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 4
Source File: PartTreeDatastoreQuery.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
/**
 * 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 5
Source File: MapBinToFromTreeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
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
Source File: Seq.java    From cyclops with 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 7
Source File: MapBinToFromTreeTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 8
Source File: MapBinToFromTreeTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 9
Source File: MapBinToFromTreeTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 10
Source File: MapBinToFromTreeTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 11
Source File: LazySeq.java    From cyclops with 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 12
Source File: MapBinToFromTreeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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
Source File: MapBinToFromTreeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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 File: MapBinToFromTreeTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 15
Source File: BankersQueue.java    From cyclops with 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 16
Source File: LazyString.java    From cyclops with 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 17
Source File: Vector.java    From cyclops with 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 18
Source File: ProcessorBuilderVerification.java    From microprofile-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@Test
public void collect() {
    Collector collector = Collectors.toList();
    Graph graph = graphFor(builder().collect(collector));
    assertSame(getAddedStage(Stage.Collect.class, graph).getCollector(), collector);
}
 
Example 19
Source File: MapBinToFromTreeTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
Collector<Integer, ?, ? extends Collection<Integer>> getCollector(Map<?, ?> m) {
    Collector<Integer, ?, ? extends Collection<Integer>> collector = m instanceof LinkedHashMap
                                                                     ? Collectors.toList()
                                                                     : Collectors.toSet();
    return collector;
}
 
Example 20
Source File: To.java    From essentials4j with 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();
}