本文整理了Java中cyclops.reactive.ReactiveSeq.collect
方法的一些代码示例,展示了ReactiveSeq.collect
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReactiveSeq.collect
方法的具体详情如下:
包路径:cyclops.reactive.ReactiveSeq
类名称:ReactiveSeq
方法名:collect
[英]Performs a mutable reduction operation on the elements of this stream. A mutable reduction is one in which the reduced value is a mutable result container, such as an ArrayList, and elements are incorporated by updating the state of the result rather than by replacing the result. This produces a result equivalent to:
R result = supplier.getValue();
Like #reduce(Object,BinaryOperator), collect operations can be parallelized without requiring additional synchronization.
This is a terminal operation.
[中]对该流的元素执行{$0$}操作。可变约化是指约化后的值是可变结果容器,例如ArrayList,通过更新结果状态而不是替换结果来合并元素。这将产生相当于以下内容的结果:
R result = supplier.getValue();
与#reduce(Object,BinaryOperator)类似,collect操作可以并行化,而无需额外的同步。
这是一个terminal operation。
代码示例来源:origin: aol/micro-server
public List<Thread> run() {
register.ifPresent( reg ->
reg.register(
apps.stream().map(app -> app.getServerData())
.collect(Collectors.toList())
.toArray(new ServerData[0])));
Map<ServerApplication,CompletableFuture> mapFutures = new HashMap<>();
apps.stream().forEach(app -> mapFutures.put(app,new CompletableFuture()));
List<Thread> threads = apps.stream().map(app -> start(app, app.getServerData().getModule(),mapFutures.get(app))).collect(Collectors.toList());
mapFutures.values().forEach(future -> get(future));
logger.info("Started {} Rest applications ", apps.size());
return threads;
}
代码示例来源:origin: aol/cyclops
/**
* @return this Stream converted to a list
*/
default List<T> toList(){
return collect(Collectors.toList());
}
代码示例来源:origin: aol/cyclops
@Test
public void testToStream() {
assertThat(none.stream().collect(Collectors.toList()).size(), equalTo(0));
assertThat(just.stream().collect(Collectors.toList()).size(), equalTo(1));
}
代码示例来源:origin: aol/cyclops
@Test
public void flattenEmptyStream() throws Exception {
assertThat(ReactiveSeq.<Integer>of(1,2,3,4,5,5,6,8,9,10).limit(10).collect(Collectors.toList()).size(),
equalTo(asList(2, 3, 4, 5, 6, 7, 0, 0, 0, 0).size()));
}
代码示例来源:origin: aol/cyclops
@Test
public void batchBySize3(){
System.out.println(of(1,2,3,4,5,6).grouped(3).collect(Collectors.toList()));
assertThat(of(1,2,3,4,5,6).grouped(3).collect(Collectors.toList()).size(),is(2));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void batchBySize() {
System.out.println("Grouped " + of(1, 2, 3, 4, 5, 6).grouped(3).collect(Collectors.toList()));
assertThat(of(1, 2, 3, 4, 5, 6).grouped(3).collect(Collectors.toList()).size(), is(2));
}
代码示例来源:origin: aol/cyclops
@Test
public void shouldReturnEmptySeqWhenZipNonEmptyWithEmpty() throws Exception {
final ReactiveSeq<Integer> zipped = nonEmpty.zip(empty, (a, b) -> a + b);
assertTrue(zipped.collect(Collectors.toList()).isEmpty());
}
代码示例来源:origin: aol/cyclops
@Test
public void zipEmpty() throws Exception {
final ReactiveSeq<Integer> zipped = empty.zip(this.<Integer>of(), (a, b) -> a + b);
assertTrue(zipped.collect(Collectors.toList()).isEmpty());
}
代码示例来源:origin: aol/cyclops
@Test
public void prepend() {
for(int k=0;k<ITERATIONS;k++){
List<String> result = of(1, 2, 3).prependAll(100, 200, 300)
.map(it -> it + "!!").collect(Collectors.toList());
assertThat(result, equalTo(Arrays.asList("100!!", "200!!", "300!!", "1!!", "2!!", "3!!")));
}
}
代码示例来源:origin: aol/cyclops
@Test
public void insertAt() {
for(int k=0;k<ITERATIONS;k++) {
List<String> result = of(1, 2, 3).insertAt(1, 100, 200, 300)
.map(it -> it + "!!").collect(Collectors.toList());
assertThat(result, equalTo(Arrays.asList("1!!", "100!!", "200!!", "300!!", "2!!", "3!!")));
}
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void shouldTrimFirstFixedSeqIfLonger() throws Exception {
final ReactiveSeq<String> first = of("A", "B", "C","D");
final ReactiveSeq<Integer> second = of(1, 2, 3);
final ReactiveSeq<String> zipped = first.zip(second, (a, b) -> a + b);
assertThat(zipped.collect(Collectors.toList()).size(),equalTo(3));
}
代码示例来源:origin: aol/cyclops
@Test
public void shouldTrimSecondFixedSeqIfLongerStream() throws Exception {
final ReactiveSeq<String> first = of("A", "B", "C");
final ReactiveSeq<Integer> second = of(1, 2, 3, 4);
final ReactiveSeq<String> zipped = first.zipWithStream(second, (a, b) -> a + b);
assertThat(zipped.collect(Collectors.toList()).size(),is(3));
}
代码示例来源:origin: aol/cyclops
@Test
public void groupedWhile(){
assertThat(Spouts.iterate(0l, i->i+1l)
.groupedWhile(i->false)
.map(l->l.get(0))
.limit(100)
.collect(Collectors.toList()).size(),equalTo(100));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void testOfType() {
assertThat(Streams.ofType(Stream.of(1, "a", 2, "b", 3, null),Integer.class).collect(Collectors.toList()),containsInAnyOrder(1, 2, 3));
assertThat(ReactiveSeq.of(1, "a", 2, "b", 3, null).ofType(Integer.class).collect(Collectors.toList()),not(containsInAnyOrder("a", "b",null)));
assertThat(ReactiveSeq.of(1, "a", 2, "b", 3, null)
.ofType(Serializable.class).toList(),containsInAnyOrder(1, "a", 2, "b", 3));
}
代码示例来源:origin: aol/cyclops
@Test
public void debounceOk(){
System.out.println(of(1,2,3,4,5,6).debounce(1,TimeUnit.NANOSECONDS).toList());
assertThat(of(1,2,3,4,5,6).debounce(1,TimeUnit.NANOSECONDS).collect(Collectors.toList()).size(),is(6));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void fixedDelay(){
SimpleTimer timer = new SimpleTimer();
assertThat(of(1,2,3,4,5,6).fixedDelay(10000,TimeUnit.NANOSECONDS).collect(Collectors.toList()).size(),is(6));
assertThat(timer.getElapsedNanoseconds(),greaterThan(60000l));
}
@Test
代码示例来源:origin: aol/cyclops
@Test
public void grouped() {
List<Vector<Integer>> list = ReactiveSeq.of(1, 2, 3, 4, 5, 6).grouped(3).collect(Collectors.toList());
System.out.println(list);
assertThat(list.get(0), hasItems(1, 2, 3));
assertThat(list.get(1), hasItems(4, 5, 6));
}
代码示例来源:origin: aol/cyclops
@Test
public void concatStreams() {
for(int k=0;k<ITERATIONS;k++) {
List<String> result = of(1, 2, 3).appendStream(of(100, 200, 300))
.map(it -> it + "!!").collect(Collectors.toList());
assertThat(result, equalTo(Arrays.asList("1!!", "2!!", "3!!", "100!!", "200!!", "300!!")));
}
}
代码示例来源:origin: aol/cyclops
@Test
public void sliding() {
List<Seq<Integer>> list = of(1, 2, 3, 4, 5, 6).sliding(2).collect(Collectors.toList());
assertThat(list.get(0), hasItems(1, 2));
assertThat(list.get(1), hasItems(2, 3));
}
代码示例来源:origin: aol/cyclops
@Test
public void shouldReturnEmptySeqWhenZipNonEmptyWithEmpty() throws Exception {
final Traversable<Integer> zipped = of(1,2,3).zip(this.<Integer>empty(), (a, b) -> a + b);
assertTrue(zipped.stream().collect(java.util.stream.Collectors.toList()).isEmpty());
}
内容来源于网络,如有侵权,请联系作者删除!