java.util.stream.Collectors#toCollection ( )源码实例Demo

下面列出了java.util.stream.Collectors#toCollection ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: reactor-core   文件: MonoStreamCollectorTest.java
@Test
public void discardIntermediateListElementsOnError() {
	final Collector<Integer, ?, Collection<Integer>> collector = Collectors.toCollection(ArrayList::new);

	Mono<Collection<Integer>> test =
			Flux.range(1, 10)
			    .hide()
			    .map(i -> {
				    if (i == 5) {
					    throw new IllegalStateException("boom");
				    }
				    return i;
			    })
			    .collect(collector);

	StepVerifier.create(test)
	            .expectErrorMessage("boom")
	            .verifyThenAssertThat()
	            .hasDiscardedExactly(1, 2, 3, 4);
}
 
源代码2 项目: immutables   文件: BindVariableConverter.java
@Override
public Object apply(Object value) {
  if (!(value instanceof Iterable)) {
    return value;
  }

  if (value instanceof HashSet || value instanceof ArrayList || value instanceof TreeSet) {
    // don't convert java collections (assume no guava implementations exists inside it)
    return value;
  }

  // transform to java collections
  Collector<Object, ?, ? extends Iterable<Object>> collector;
  if (value instanceof SortedSet) {
    collector = Collectors.toCollection(TreeSet::new);
  } else if (value instanceof Set) {
    collector = Collectors.toCollection(HashSet::new);
  } else {
    collector = Collectors.toList();
  }

  return StreamSupport.stream(((Iterable<Object>) value).spliterator(), false).map(this::apply).collect(collector);
}
 
源代码3 项目: reactor-core   文件: MonoStreamCollectorTest.java
@Test
public void discardIntermediateListElementsOnCancel() {
	final Collector<Long, ?, Collection<Long>> collector = Collectors.toCollection(ArrayList::new);

	StepVerifier.withVirtualTime(() ->
			Flux.interval(Duration.ofMillis(100))
			    .take(10)
			    .collect(collector)
	)
	            .expectSubscription()
	            .expectNoEvent(Duration.ofMillis(210))
	            .thenCancel()
	            .verifyThenAssertThat()
	            .hasDiscardedExactly(0L, 1L);
}
 
源代码4 项目: vividus   文件: ExcelSheetParser.java
private static <T> Collector<T, ?, LinkedList<T>> toLinkedList()
{
    return Collectors.toCollection(LinkedList::new);
}
 
源代码5 项目: hugegraph   文件: HugeTask.java
private static <V> Collector<V, ?, Set<V>> toOrderSet() {
    return Collectors.toCollection(InsertionOrderUtil::newSet);
}
 
源代码6 项目: scipio-erp   文件: UtilStream.java
public static <T> Collector<T, ?, List<T>> toArrayList(int initialCapacity) {
    return Collectors.toCollection(() -> new ArrayList<T>());
}
 
源代码7 项目: cyclops   文件: SetX.java
static <T> Collector<T, ?, SetX<T>> setXCollector() {
    return Collectors.toCollection(() -> SetX.of());
}
 
源代码8 项目: cyclops   文件: SetX.java
static <T> Collector<T, ?, Set<T>> defaultCollector() {
    return Collectors.toCollection(() -> new HashSet<>());
}
 
源代码9 项目: cyclops   文件: SortedSetX.java
static <T> Collector<T, ?, SortedSet<T>> defaultCollector() {
    return Collectors.toCollection(() -> new TreeSet<T>(
                                                        (Comparator) Comparator.<Comparable> naturalOrder()));
}
 
源代码10 项目: cyclops   文件: ListX.java
/**
 * @return A JDK 8 Collector for converting Streams into ListX instances
 */
static <T> Collector<T, ?, ListX<T>> listXCollector() {
    return Collectors.toCollection(() -> ListX.of());
}
 
源代码11 项目: cyclops   文件: ListX.java
/**
 * @return An Array List Collector
 */
static <T> Collector<T, ?, List<T>> defaultCollector() {
    return Collectors.toCollection(() -> new ArrayList<>());
}
 
源代码12 项目: semagrow   文件: PlanCollectionImpl.java
public static Collector<Plan, ?, PlanCollection> toPlanCollection(TupleExpr logical) {
    return Collectors.toCollection(() -> new PlanCollectionImpl(logical));
}
 
源代码13 项目: semagrow   文件: PlanCollectionImpl.java
public static Collector<Plan, ?, PlanCollection> toPlanCollection(Set<TupleExpr> logical) {
    return Collectors.toCollection(() -> new PlanCollectionImpl(logical));
}
 
源代码14 项目: gatk   文件: SVUtils.java
/**
 * Provides a stream collector that will collect items into an array list with a given initial capacity.
 */
public static <T> Collector<T, ?, ArrayList<T>> arrayListCollector(final int size) {
    return Collectors.toCollection( () -> new ArrayList<>(size));
}
 
源代码15 项目: buck   文件: TreeBackedProcessorWrapper.java
private Collector<TypeElement, ?, Set<TypeElement>> toSet() {
  return Collectors.toCollection(LinkedHashSet::new);
}
 
源代码16 项目: buck   文件: TreeBackedRoundEnvironment.java
private Collector<Element, ?, Set<Element>> toSet() {
  return Collectors.toCollection(LinkedHashSet::new);
}