cyclops.reactive.ReactiveSeq.count()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(87)

本文整理了Java中cyclops.reactive.ReactiveSeq.count方法的一些代码示例,展示了ReactiveSeq.count的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReactiveSeq.count方法的具体详情如下:
包路径:cyclops.reactive.ReactiveSeq
类名称:ReactiveSeq
方法名:count

ReactiveSeq.count介绍

[英]Returns the count of elements in this stream. This is a special case of a reduction and is equivalent to:

return mapToLong(e -> 1L).sum();

This is a terminal operation.
[中]返回此流中元素的计数。这是{$0$}的一个特例,相当于:

return mapToLong(e -> 1L).sum();

这是一个terminal operation

代码示例

代码示例来源:origin: aol/cyclops

@Test
public void limitArray() throws InterruptedException{
  List<Integer> list= new ArrayList<>();
  for(int i=0;i<1000;i++)
    list.add(i);
  assertThat(ReactiveSeq.of(list.toArray())
       .limit(100)
       .count(),equalTo(100L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void reversedRangeWithReverse(){
  assertThat(ReactiveSeq.range(10, -10).reverse().count(),equalTo(20L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void skipArray() throws InterruptedException{
  List<Integer> list= new ArrayList<>();
  for(int i=0;i<1000;i++)
    list.add(i);
  assertThat(ReactiveSeq.of(list.toArray())
       .skip(100)
       .count(),equalTo(900L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void limitArray() throws InterruptedException{
  List<Integer> list= new ArrayList<>();
  for(int i=0;i<1000;i++)
    list.add(i);
  assertThat(Spouts.of(list.toArray())
       .limit(100)
       .count(),equalTo(100L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void skipArray() throws InterruptedException{
  List<Integer> list= new ArrayList<>();
  for(int i=0;i<1000;i++)
    list.add(i);
  assertThat(Spouts.of(list.toArray())
       .skip(100)
       .count(),equalTo(900L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void limitList() throws InterruptedException{
  List<Integer> list= new ArrayList<>();
  for(int i=0;i<1000;i++)
    list.add(i);
  assertThat(Spouts.fromIterable(list)
       .limit(100)
       .count(),equalTo(100L));
}

代码示例来源:origin: aol/cyclops

@Test
public void testParallel(){
  for(int k=0;k<1000;k++) {
    System.out.println("Iteration " + k);
    assertThat(ReactiveSeq.range(0, 1000)
        .parallel(s -> s.map(i -> i * 2))
        .count(), equalTo(1000L));
  }
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void skipList() throws InterruptedException{
  List<Integer> list= new ArrayList<>();
  for(int i=0;i<1000;i++)
    list.add(i);
  assertThat(Spouts.fromIterable(list)
       .skip(100)
       .count(),equalTo(900L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void reversedRangeInt(){
  assertThat(Spouts.range(10, -10).count(),equalTo(20L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void negative(){
  assertThat(ReactiveSeq.range(-1000,Integer.MAX_VALUE)
      .limit(100)
      .count(),equalTo(100L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void limitRange() throws InterruptedException{
  assertThat(ReactiveSeq.range(0,Integer.MAX_VALUE)
       .limit(100)
       .count(),equalTo(100L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void negativeLong(){
  assertThat(Spouts.rangeLong(-1000L,Long.MAX_VALUE)
      .limit(100)
      .count(),equalTo(100L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void streamUntil(){
  assertThat(Eval.always(()->times++)
          .peek(System.out::println)
          .streamUntil(i->i>10).count(),equalTo(11L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void streamUntilTime(){
  assertThat(Eval.always(()->times++)
    .peek(System.out::println)
    .streamUntil(1000, TimeUnit.MILLISECONDS).count(),greaterThan(10L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void skipRangeReversed() throws InterruptedException{
  assertThat(Spouts.range(0,1000)
       .skip(100).reverse()
       .count(),equalTo(900L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void skipRangeReversed() throws InterruptedException{
  assertThat(ReactiveSeq.range(0,1000)
       .skip(100).reverse()
       .count(),equalTo(900L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void multipleGrouped() throws Exception {
  final Streamable<Integer> fixed = Streamable.fromStream(Stream.of(5, 7, 9,10));
  assertThat(fixed.stream().grouped(3).elementAt(0).toOptional().get(),equalTo(Vector.of(5,7,9)));
  assertThat(fixed.stream().grouped(3).count(),equalTo(2l));
}

代码示例来源:origin: aol/cyclops

@Test
public void prependAppend(){
  assertThat(of(1)
      .prependStream(Stream.of(2)).append(3).prepend(4).appendAll(5,6)
      .prependAll(7,8)
      .insertAt(4,9).deleteBetween(1,2)
      .insertStreamAt(5,Stream.of(11,12)).stream().count(),equalTo(10L));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void limit(){
  assertThat(of(1,2,3).limit(2).count(),equalTo(2l));
  of(10,1,10,2,10,3).skip(1).printOut();
  of(1,2,3).flatMap(i->Stream.of(10,i)).skip(1).printOut();
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void groupedShorter() throws Exception {
  final Streamable<Integer> fixed = Streamable.fromStream(of(5, 7, 9));
  assertThat(fixed.stream().grouped(4).elementAtAndStream(0)._1(),equalTo(Vector.of(5,7,9)));
  assertThat(fixed.stream().grouped(4).count(),equalTo(1l));
}

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法